import random #method for game loop def Game(): #asks the user how many rounds Num_Rounds= input("How many Rounds would you like to Play?: ") Num_Rounds=int(Num_Rounds) computer_list=["Rock","Paper","Scissor"] user_wins=0 computer_wins=0 #does the game looop for as many rounds as the user asks for i in range(0,Num_Rounds): #asks for the users input user = input("Pick Rock, Paper, or Scissor: ") #randomly selects the computer's choice computer=random.choice(computer_list) #compares the users and the computer's choices #if the user wins the number of user wins is incremented #if the computer wins the number of computer wins is incremented if(user=="Rock" or user=="rock"): if(computer=="Scissor"): print("Computer picked Scissor") print("You Win!") user_wins+=1 if(computer=="Rock"): print("Computer picked Rock") print("It's a Tie!") if(computer=="Paper"): print("Computer picked Paper") print("Computer wins!") computer_wins+=1 if(user=="Paper" or user=="paper"): if(computer=="Scissor"): print("Computer picked Scissor") print("Computer wins!") computer_wins+=1 if(computer=="Rock"): print("Computer picked Rock") print("You Win!") user_wins+=1 if(computer=="Paper"): print("Computer picked Paper") print("It's a Tie!") if(user=="Scissor" or user=="scissor"): if(computer=="Scissor"): print("Computer picked Scissor") print("It's a Tie!") if(computer=="Rock"): print("Computer picked Rock") print("Computer wins!") computer_wins+=1 if(computer=="Paper"): print("Computer picked Paper") print("You Win!") user_wins+=1 #prints the number of wins print("You won "+str(user_wins)+" rounds out of "+str(Num_Rounds)) #compares the users wins and the computers wins and outputs the winner if(user_wins>computer_wins): print("YOU WIN!") if(user_wins<computer_wins): print("You Lose!") if(user_wins==computer_wins): print("It's a Tie!") #asks the user if they would like to play again decision=input("Would you like to play again?: ") if(decision=="Yes" or decision=="yes"): Game() 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