player1_score = 0 player2_score = 0 #game function def game(): x = input('What does Player 1 choose: ') #first question print(x) y = input('What does Player 2 choose: ') #second question print(y) if (x == 'Rock' and y == 'Rock') or (x == 'Paper' and y == 'Paper') or (x == 'Scissors' and y == 'Scissors'): print('It is a tie\n') global player1_score global player2_score player1_score += 1 player2_score += 1 playAgain() elif (x == 'Paper' and y == 'Rock') or (x == 'Rock' and y == 'Scissors') or (x == 'Scissors' and y == 'Paper'): print('Player 1 wins!\n') player1_score += 1 playAgain() elif (x == 'Scissors' and y == 'Rock') or (x == 'Rock' and y == 'Paper') or (x == 'Paper' and y == 'Scissors'): print('Player 2 wins!\n') player2_score += 1 playAgain() else: print('Incorrect inputs\n') playAgain() #play again function def playAgain(): user = input('Do you want to play again (yes or no)? ') #third question print(user) if user == 'yes': game() elif user == 'no': global player1_score global player2_score print'Game Over\n' print'Results: Player 1:', player1_score, ', Player 2: ', player2_score if player1_score > player2_score: print('Player 1 wins the game!') elif player2_score > player1_score: print('Player 2 wins the game!') else: print('The game ends in a tie') else: print('Please say yes or no ') playAgain() game()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question