#Deepal Sanghrajka #Girls Who Code #2018 SIP Technical Project import random def run_game() -> None: ''' Runs the Rock, Paper, Scissors Game based on user input ''' player_score = 0 computer_score = 0 print('Let\'s play Rock, Paper, Scissors! Best of 3.') print('You can quit anytime by entering Quit.') while player_score < 2 and computer_score < 2 and player_score + computer_score < 3: player_options = ['Rock', 'Paper', 'Scissors'] random_player = player_options[random.randint(0, 2)] player_input = input('\nEnter your choice: ').strip() if player_input == 'Rock': print('The computer\'s Choice:', random_player) if random_player == 'Rock': print('Tie!') print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif random_player == 'Paper': print('Paper beats Rock!') computer_score += 1 print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif random_player == 'Scissors': print('Rock beats Scissors!') player_score += 1 print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif player_input == 'Paper': print('The computer\'s Choice:', random_player) if random_player == 'Paper': print('Tie!') print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif random_player == 'Scissors': print('Scissors beats Paper!') player_score += 1 print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif random_player == 'Rock': print('Paper beats Rock!') computer_score += 1 print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif player_input == 'Scissors': print('The computer\'s Choice:', random_player) if random_player == 'Scissors': print('Tie!') print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif random_player == 'Rock': print('Rock beats Scissors!') computer_score += 1 print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif random_player == 'Paper': print('Scissors beats Paper!') player_score += 1 print('Your Score:', player_score) print('The computer\'s Score:', computer_score) elif player_input == 'Quit': print('Thanks for playing') break else: print('Not A Valid Choice. Try Again.') else: if player_score > computer_score: print('\nYou win!') elif player_score < computer_score: print('\nThe computer wins!') while True: new_game = input('\nWant to play again? Enter Yes or No: ').strip() if new_game == 'Yes': run_game() elif new_game == 'No': print('\nThanks for playing!') break else: print('\nNot a Valid Choice. Try Again.') run_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