Last active
April 27, 2017 14:55
-
-
Save MuddyBootsCode/8de6e2cc409c92e9e7f3ca3a5b37e3c8 to your computer and use it in GitHub Desktop.
Rock Paper Scissors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code plays a game of rock paper scissors | |
import random | |
# Creates the computers choice | |
def roshambo(randomChoice): | |
if randomChoice == 1: | |
return 'scissors' | |
elif randomChoice == 2: | |
return 'rock' | |
else: | |
return 'paper' | |
# Matches computers choice with the players choice to find a winner | |
def rock_paper_scissors(player_choice): | |
if player_choice.lower() == 'rock' and auto_play not in ('paper', 'rock'): | |
return 'Winner!' | |
elif player_choice.lower() == 'scissors' and auto_play not in ('scissors', 'rock'): | |
return 'Winner!' | |
elif player_choice.lower() == 'paper' and auto_play not in ('paper', 'scissors'): | |
return 'Winner!' | |
elif player_choice.lower() == auto_play: | |
return 'Draw!' | |
else: | |
return 'You lose!' | |
# Keeps playing RPS as long as the player says yes | |
keep_playing = True | |
while keep_playing == True: | |
play = input(str("Would you like to play rock, paper, scissors? yes or no?\n")) | |
if play.lower() == 'yes': | |
player_choice = input(str("Ok! what's your choice?\n")) | |
r = random.randint(1, 3) | |
auto_play = roshambo(r) | |
result = rock_paper_scissors(player_choice) | |
print('{}, You chose {} and I chose {}'.format(result, player_choice, auto_play)) | |
elif play.lower() == 'no': | |
keep_playing = False | |
else: | |
print("I'm sorry I don't understand.") | |
print('Ok take care!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment