''' Caroline Bhupathi Rock, Paper, Scissors Game ''' import random def get_computer_move(): return random.choice(['rock', 'paper', 'scissors']) def valid_move(move): move = str.lower(move) if move == 'rock' or move == 'paper' or move == 'scissors': return True else: return False def get_player_move(): move = input('Please enter a move: ') while valid_move(move) == False: move = input('Please enter a valid move (rock, paper, or scissors): ') return str.lower(move) def rock_paper_scissors(): player_name = input("Please enter your name: ") player_score = 0 computer_score = 0 while player_score < 3 and computer_score < 3: player_move = get_player_move() computer_move = get_computer_move() print('The Computer chose', computer_move) if player_move == 'rock': if computer_move == 'rock': print("It's a tie!") elif computer_move == 'paper': print('The Computer wins this round!') computer_score += 1 elif computer_move == 'scissors': print(player_name , "wins this round!") player_score += 1 if player_move == 'paper': if computer_move == 'rock': print(player_name , "wins this round!") player_score += 1 elif computer_move == 'paper': print("It's a tie!") elif computer_move == 'scissors': print('The Computer wins this round!') computer_score += 1 if player_move == 'scissors': if computer_move == 'rock': print('The Computer wins this round!') computer_score += 1 elif computer_move == 'paper': print(player_name , "wins this round!") player_score += 1 elif computer_move == 'scissors': print("It's a tie!") print(player_name, ': ', str(player_score)) print('Computer : ', str(computer_score)) if player_score > computer_score: print(player_name, 'is the winner!') else: print('The Computer is the winner!')
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