Python Programming: An Introduction to Computer Science

(Nora) #1
10.6. EXERCISES 175


  1. RedotheregressionproblemfromChapter8 usingaRegressionclass.Yournewclasswillkeep
    trackofthevariousquantitiesthatareneededtocomputea lineofregresion(therunningsumsofx,y,
    x^2 andxy)Theregressionclassshouldhave thefollowingmethods.


init Createsa new regressionobjecttowhichpointscanbeadded.
addPointAddsa pointtotheregressionobject.
predictAcceptsa valueofxasa parameter, andreturnsthevalueofthecorrespondingyontheline
ofbestfit.

Note:Yourclassmightalsousesomeinternalhelpermethodstodosuchthingsascomputetheslope
oftheregressionline.


  1. Implementa cardclassthatrepresentsa playingcard.Useyourclasstowritea programthat“deals”
    a randomhandofcardsanddisplaysthemina graphicswindow. Youshouldbeabletofinda freely
    availablesetofcardimagestodisplayyourcardsbysearchingontheInternet.

Free download pdf