Python Programming: An Introduction to Computer Science
12.3. CASESTUDY: DICEPOKER 213 from dice importDice d = Dice() d.values() [6, 3, 3, 6, 5] d.score() (’Two Pairs’, 5) d.roll([ ...
214 CHAPTER12. OBJECT-ORIENTEDDESIGN Thiscodeonlyreallyhandlesthescoringaspectofa round.Anytimenew informationmustbeshowntothe u ...
12.3. CASESTUDY: DICEPOKER 215 def setMoney(self,amt): print "Youcurrently have $%d." % (amt) def setDice(self,values): print "D ...
216 CHAPTER12. OBJECT-ORIENTEDDESIGN Dice: [3, 2, 1, 1, 1] Enter list of whichto change ([] to stop) [0,1] Dice: [5, 6, 1, 1, 1] ...
12.3. CASESTUDY: DICEPOKER 217 Figure12.2:GUIinterfaceforvideodicepoker. Unlike thebuttonsin thecalculatorprogram,thebuttonsofou ...
218 CHAPTER12. OBJECT-ORIENTEDDESIGN if b.clicked(p): returnb.getLabel() # function exit here. Theotherwidgetsinourinterfacewill ...
12.3. CASESTUDY: DICEPOKER 219 banner = Text(Point(300,30),"Python Poker Parlor") banner.setSize(24) banner.setFill("yellow2") b ...
220 CHAPTER12. OBJECT-ORIENTEDDESIGN self.money.setText("$%d" % (amt)) def showResult(self,msg, score): if score > 0: text = ...
12.4. OOCONCEPTS 221 self.dice[i].setColor("gray") else: # User clicked Roll or Score for d in self.dice: # Revert appearance of ...
222 CHAPTER12. OBJECT-ORIENTEDDESIGN Froma designstandpoint,encapsulationalsoprovidesa criticalserviceofseparatingtheconcernsof ...
12.5. EXERCISES 223 We couldhave usedinheritancetobuildourpokerprogram.WhenwefirstwrotetheDieViewclass, it didnotprovidea wayofc ...
224 CHAPTER12. OBJECT-ORIENTEDDESIGN ...
Chapter 13 Algorithm Analysis and Design Ifyouhave workedyourwaythroughtothispointinthebook,youarewellonthewaytobecominga progra ...
226 CHAPTER13. ALGORITHMANALYSISANDDESIGN nums = [3,1,4,2,5] nums.index(4) 2 Infact,theonlydifferencebetweenoursearchfunct ...
13.1. SEARCHING 227 couldbeanywhereinthelist,sowestartwithvariableslowandhighsettothefirstandlastpositionsof thelist,respectivel ...
228 CHAPTER13. ALGORITHMANALYSISANDDESIGN timesaslong,etc.Ingeneral,theamountoftimerequiredis linearlyrelatedtothesizeofthelistn ...
13.2. RECURSIVEPROBLEM-SOLVING 229 Algorithm: binarySearch-- search for x in range nums[low] to nums[high] mid = (low + high)/ 2 ...
230 CHAPTER13. ALGORITHMANALYSISANDDESIGN Thereareoneormorebasecasesforwhichnorecursionis required. Whenthedefinitionis recursi ...
13.3. SORTINGALGORITHMS 231 willcutthesizeoftheproblemin halfeachtime.Inorderto dothis,weneedtospecifytherangeoflocations inthel ...
232 CHAPTER13. ALGORITHMANALYSISANDDESIGN nums[0] = nums[10] Butthiswipesoutthevaluecurrentlyinnums[0]; it reallyneedstobemovedt ...
«
5
6
7
8
9
10
11
12
13
14
»
Free download pdf