import random def word(num): if num == 0: return "ROCK" elif num == 1: return "PAPER" else: return "SCISSORS" def game(): print("***************************************************") print("Let's Play: ROCK, PAPER, SCISSORS!") keep_playing = True while keep_playing: playgame() print("Do you want to play again: Yes[0] or No[1]?") again = int(input()) if again == 1: print("Thank you for playing!") keep_playing = False print("***************************************************") def playgame(): print("Rock[0], Paper[1], or Scissors[2]?") user = int(input()) while user not in range(0,3): print("*Invalid Play*: please select Rock[0], Paper[1], or Scissors[2]:") user = int(input()) comp = random.randint(0,3) print("You played {0}".format(word(user))) print("Computer played {0}".format(word(comp))) if user == comp: print("Tie! Play again!") playgame() elif (user == 0 and comp == 2) or (user == 1 and comp == 0) or (user == 2 and comp == 1): print("{0} beats {1}: You beat the computer! Congratulations!".format(word(user), word(comp))) else: print("{0} beats {1}: You lost! Better luck next time!".format(word(comp), word(user))) 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