Python Programming: An Introduction to Computer Science

(Nora) #1
9.5.OTHERDESIGNTECHNIQUES 151

if name == ’main’:simOneGame()


YoucanseethatI have addeda printstatementat thebottomoftheloop.Printingoutthescoresaswego
alongallowsustoseethattheprototypeis playinga game.Hereis someexampleoutput.


1 0

1 0

1 0

2 0

2 0

2 1

2 1

3 1

3 1

3 1

3 1

3 2

7 6

7 7

7 8

It’s is notpretty, butit showsthatwehave gottenthescoringandchangeofserviceworking.
We couldthenworkonaugmentingtheprograminphases.Here’s a projectplan.


Phase 1 Initialprototype.Play 30 rallieswheretheserveralwayshasa 50%chanceofwinning.Printout
thescoresaftereachrally.


Phase 2 Addtwo parameterstorepresentdifferentprobabilitiesforthetwo players.


Phase 3 Playthegameuntiloneoftheplayersreaches 15 points.Atthispoint,wehave a workingsimulation
ofa singlegame.


Phase 4 Expandtoplaymultiplegames.Theoutputis thecountofgameswonbyeachplayer.


Phase 5 Buildthecompleteprogram.Addinteractive inputsanda nicelyformattedreportoftheresults.


Spiraldevelopmentis particularlyusefulwhendealingwithnew orunfamiliarfeaturesortechnologies.
It’s helpfulto“getyourhandsdirty”witha quickprototypejusttoseewhatyoucando. Asa novice
programmer, everythingmayseemnewtoyou,soprototypingmightprove useful.If full-blowntop-down
designdoesnotseemtobeworkingforyou,trysomespiraldevelopment.


9.5.2 TheArtofDesign


It is importanttonotethatspiraldevelopmentis notanalternative totop-downdesign.Rather, they arecom-
plementaryapproaches.Whendesigningtheprototype,youwillstillusetop-downtechniques.InChapter12,
youwillseeyetanotherapproachcalledobject-orienteddesign.
Thereis no“onetrueway”ofdesign.Thetruthis thatgooddesignis asmucha creative processasa
science.Designscanbemeticulouslyanalyzedafterthefact,but therearenohardandfastrulesforproducing
a design.Thebestsoftwaredesignersseemto employ a varietyoftechniques.Youcanlearnabouttechniques
byreadingbookslike thisone,but bookscan’t teachhow andwhentoapplythem.Thatyouhave tolearnfor
yourselfthroughexperience.Indesignasinalmostanything,thekey tosuccessispractice.

Free download pdf