WEEK08: more top-down design
---------------------------------------------------------------
W: another TDD example
REVIEW:
- Quiz 4 this Friday (functions, while loops, TDD, File I/O)
- Lab 7 design.py files due this Thur
- python design.py should run without errors!!!
- functions that are only one line are probably not good functions
(it's expensive to call a function)
- this is NOT a good design:
def main():
playGame()
def playGame():
"""plays the game"""
return
REVIEW of wofdesign.py:
- think about the program's data, and how it gets passed to/from functions
- each function should run and return a *realistic* value:
def spin(answer, puzzlesofar, wheel, winnings, lettersguessed):
"""
takes care of spinning wheel and geting guess,
should return amount of money
"""
return 100
YOUR TURN:
- let's design another short game:
$ python rps.py
Rock-Paper-Scissors v0.1
rock, paper, or scissors? --> rock
You chose: rock
I chose: scissors
you win...
Game over...
- here's my main() function:
def main():
"""make comp choice, then play out RPS game"""
print "\nRock-Paper-Scissors v0.1\n"
cc = choice(["rock", "paper", "scissors"])
uc = getUserChoice()
print "You chose: %s" % (uc)
print " I chose: %s" % (cc)
displayWinner(cc, uc)
- write the other function stubs and get this to run
- once it runs, think about how to fill in the functions
------------------------------------------------------------
A HARDER CHALLENGE: keep track of who wins (only if you have time)
$ python rpsTO4.py
Rock-Paper-Scissors v0.2 (first to 4)
rock, paper, or scissors? --> r
You chose: rock
I chose: paper
I WIN!!!
SERIES RESULTS: user wins = 0 computer wins = 1
--------------------------------------------------
rock, paper, or scissors? --> p
You chose: paper
I chose: paper
it's a draw...
SERIES RESULTS: user wins = 0 computer wins = 1
--------------------------------------------------
rock, paper, or scissors? --> s
You chose: scissors
I chose: rock
I WIN!!!
SERIES RESULTS: user wins = 0 computer wins = 2
--------------------------------------------------
rock, paper, or scissors? -->