I am creating a very simple Rock, Paper, Scissors game, using Python, but can't get past this problem. Every time I type in the answers into Command Prompt, it outputs the message 'Invalid input, try again!' which is what I have told it to do if there is an invalid input. But, I am not putting an invalid input in, this keeps printing out instead of 'Rock wins!' etc. And the 'Do you want to play again? (True or False)' prints out before the answer, and when I type True, it comes up with the Invalid input. I have tried moving around the rematch line, but nothing is working.
Here is the game, showing the error:
What's your name? Bob And your name? Bill Bob, Do you want to choose rock, paper, or scissors? rock Bill, Do you want to choose rock, paper, or scissors? paper Do you want to play again? (True or False) True Invalid input, try again! Here is my code:
import sys user1 = input('What\'s your name?') user2 = input('And your name?') user1_answer = input('%s, Do you want to choose rock, paper, or scissors?' % user1) user2_answer = input('%s, Do you want to choose rock, paper, or scissors?' % user2) def compare(u1, u2): if u1 == u2: return('It\'s a tie!') elif u1 == 'rock': if u2 == 'scissors': return('Rock wins!') else: ('Paper wins!') elif u1 == 'scissors': if u2 == 'rock': return('Rock wins!') else: ('Paper wins!') elif u1 == 'scissors': if u2 == 'paper': return('Scissors wins!') else: ("Rock wins!") elif u1 == 'paper': if u2 == 'scissors': return('Scissors wins!') else: ('Rock wins!') elif u1 == 'paper': if u2 == 'rock': return('Paper wins!') else: ('Scissors wins!') elif u1 == 'rock': if u2 == 'paper': return('Paper wins!') else: ('Scissors wins!') else: return('Invalid input, try again!') rematch = bool(input('Do you want to play again? (True or False)')) print(compare(user1_answer, user2_answer))
print(repr(user1_answer))etc