[Tutor] Help!

rmntcverses at aol.com rmntcverses at aol.com
Fri Oct 7 18:32:13 CEST 2011


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)




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)
    
    
        
    
    
     
        
        




            
    






        
        


  
    



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111007/ddc94f0c/attachment-0001.html>


More information about the Tutor mailing list