[Tutor] Help!

Alex Hall mehgcap at gmail.com
Fri Oct 7 20:37:11 CEST 2011


On 10/7/11, rmntcverses at aol.com <rmntcverses at aol.com> wrote:
> I need serious help with this Rock, Paper, Scissors program. The program
> runs smoothly but I can't get the score to print. Please help me with this
> one aspect! Here is my code right now:
>
>
>
> import random
>
>
> def computerrockPaperScissors():
>     selection = random.randint(0, 2)
>     if selection == 0:
>         y = 'r'
>     if selection == 1:
>         y = 's'
>     if selection == 2:
>         y = 'p'
>     return y
>
>
> def humanrockPaperScissors():
>     x = input("Make your selection: r (rock), p (paper), s (scissors), q
> (quit)")
>     return x
>
>
> humanWins= 0
> computerWins= 0
> ties= 0
>
>
> def compareSelection(x, y):
>     if x == 'r' and y == 'r':
>         print("You picked rock, I picked rock. We tied!")
>         ties+= 1
>     elif x == 'r' and y == 's':
>         print("You picked rock, I picked scissors. You won!")
>         humanWins+= 1
>     elif x == 'r' and y == 'p':
>         print("You picked rock, I picked paper. I won!")
>         computerWins+= 1
>     elif x == 's' and y == 's':
>         print("You picked scissors, I picked scissors. We tied!")
>         ties+= 1
>     elif x == 's' and y == 'r':
>         print("You picked scissors, I picked rock. I won!")
>         computerWins+= 1
>     elif x == 's' and y == 'p':
>         print("You picked scissors, I picked paper. You won!")
>         humanWins+= 1
>     elif x == 'p' and y == 'p':
>         print("You picked paper, I picked paper. We tied!")
>         ties+= 1
>     elif x == 'p' and y == 's':
>         print("You picked paper, I picked scissors. I won!")
>         computerWins+= 1
>     elif x == 'p' and y == 'r':
>         print("You picked paper, I picked rock. You won!")
>         humanWins+= 1
>     elif x == 'q':
>         print("Game over.")
>         print(humanWins, computerWins, ties)

This only prints when the user enters 'q', not when the below for loop ends.
>
>
> def rockPaperScissors():
>     print("Let's play Rock Paper Scissors. Rock beats scissors, scissors
> beats paper and paper beats rock.")
>     for i in range(999):
>         computerSelection = computerrockPaperScissors()
>         humanSelection = humanrockPaperScissors()
>         result = compareSelection(humanSelection, computerSelection)
Now, after the loop, print the win statistics since they will only
print once the loop exits. If you do that, and the user hits q, the
stats will print twice. I would change your for loop to:
while 1:
 ... #your code
 if humanSelection=='q': break
printStats() #print win/loss numbers, you must make that function if you want

This way, the player can go as many times as they want, even over
1000, and the stats will always print.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list