#Christina Chou #Rock Paper Scissors Game import random import string playgame=True while playgame: choices=['rock','paper', 'scissors'] #Gets the user's move user=(input('Enter your move: ')).lower() valid_move=False def computer_move(): return choices[random.randint(0,2)] #Checks if the move is valid def is_valid_move(): if user in choices: return True else: return False print(user) #If the move is valid, computer makes a move if is_valid_move(): comp_choice=computer_move() print('I chose '+comp_choice) if(user==comp_choice): print("It's a draw!") elif((user=='rock' and comp_choice=='paper') or (user=='scissors' and comp_choice=='rock') or (user=='paper' and comp_choice=='scissors')): print('You lose.') else: print('You win!') else: print('Invalid Move. Please type rock, paper, or scissors.') #If the user does not want to play again, exit the game print("Play again? y or n") playagain=input() print(playagain) if playagain!='y': playgame=False
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