#Anah Lewi #Teaching Staff Position: Teacher's Assistant import random selection = ['r', 'p', 's' ] #function that checks to see if the players choice is in list def playerInput(choice): return choice in selection #loop that allows player to play game multiple times while True: player= str(input("rock (r), paper (p), scissors (s)?")).lower() computer = random.choice(selection) #below there are multiple conditionals to check to see who won the round if playerInput(player) == False: player= str(input("Choose Again! rock (r), paper (p), scissors (s)?")).lower() elif playerInput(player): if player == computer: print('draw') elif player == "r" and computer == "p": print('Computer chose Paper') print('Computer wins!') elif player == "s" and computer == "p": print('Computer chose Paper') print('You win!') elif player == "r" and computer == "s": print('Computer chose Scissors') print('You win!') elif player == "s" and computer == "r": print('Computer chose Rock') print('computer wins!') elif player == "p" and computer == "s": print('Computer chose Scissors') print('Computer wins!') else: print('Computer chose Rock') print('You win!') choice = str(input("Are you finished? Yes (y) or No (n)")).lower() if choice == 'y': break
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