#Jasminesrockpaperscissors #Author: Jasmine White import random def main(): cpscore = 0 #computer score userscore = 0 #user score rounds = 0 #number of rounds print("This rock, paper, scissors game will be out of 3 rounds.") while rounds != 3: #continue this loop until round 3 user = input("please choose(r)rock,(p)paper,(s)scissors:") #takes input from the user, their choice of rock, paper, scissors cp = random.choice(["r","p","s"]) #gives the computer the random choice of rock, paper, scissors print("Your choice:", user) print("Computer's choice:", cp) #scenarios if the user wins if user == cp: #if the user & the computer chose the same option print "Tie Try Again" print("Tie Try Again\n") else: if user == "r" and cp == "s": #if user chose rock & computer chose scissors print("You Won! rocks beats paper\n") userscore = userscore + 1 #adds 1 point to the user's score rounds = rounds + 1 #update the round else: if user == "p" and cp == "r": #if user chose paper & computer chose rock print("You Won! paper beats rock\n") userscore = userscore + 1 #adds 1 point to the user's score rounds = rounds + 1 #update the round else: if user == "s" and cp == "p": #if user chose scissors & computer chose paper print("You Won! scissors beats paper\n"); userscore = userscore + 1 #adds 1 point to the user's score rounds = rounds + 1 #update the round else: #the rest of the scenarios are if the computer wins print("You Lost!\n") cpscore = cpscore + 1 #adds 1 point to the user's score rounds = rounds + 1 #update the round if userscore > cpscore: #if the user has a greater scrore that the computer print("You Won! Best 2 out of 3 games\n") else: print("Computer Won! Best 2 out of 3 games\n") main()
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