# a game of rock, paper, scissors by Christie Ulloa # imported random functions import random # ask users rock, paper, or scissors using # 1 = rock, 2 = paper, 3 = scissors userChoice = int(input('Rock, paper, or scissors? Type 1 for rock, 2 for paper, or 3 for scissors. ')) # computer generates rock, paper, or scissors compChoice = random.randint(1,3) ## computer choice if compChoice == 1: compString = "rock" elif compChoice == 2: compString = "paper" else: compString = "scissors" # possible results for a tie if userChoice == 1 and compChoice == 1: result = "tie" if userChoice == 2 and compChoice == 2: result = "tie" if userChoice == 3 and compChoice == 3: result = "tie" # results if user chooses rock1 if userChoice == 1 and compChoice == 2: result = "lose" if userChoice == 1 and compChoice == 3: result = "win" # results if user chooses paper if userChoice == 2 and compChoice == 1: result = "win" if userChoice == 2 and compChoice == 3: result = "lose" # results if user choose scissors if userChoice == 3 and compChoice == 1: result = "lose" if userChoice == 3 and compChoice == 2: result = "win" # prints computer's choice and the game result print(" I choose " + compString + ". You " + result + "!")
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