import random def word(num): if num == 0: return "rock" elif num == 1: return "paper" else: return "scissors" def number(word): if word == "rock": return 0 elif word == "paper": return 1 else: return 2 def playgame(): winner = 0 while winner == 0: print("Rock[0], Paper[1], or Scissors[2]?") user_input = input() comp_input = random.randrange(0,3) print('You chose: ' + word(user_input)) print('Computer chose: ' + word(comp_input)) if user_input == comp_input: print("Tie! Play again!") elif (user_input == 0 and comp_input == 2) or (user_input == 1 and comp_input == 0) or (user_input == 2 and comp_input == 1): print("You beat the computer! Congratulations!") winner = 1 else: print("You lost! The computer outsmarted you this time!") winner = 2 playgame()
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