Last active
November 29, 2018 09:49
-
-
Save malep2007/09b73456de0f6d0d00f04ac0621b7129 to your computer and use it in GitHub Desktop.
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
def validate(hand): | |
if hand < 0 or hand > 2: | |
return False | |
return True | |
def print_hand(hand, name='Guest'): | |
hands = ['Rock', 'Paper', 'Scissors'] | |
print(name + ' picked: ' + hands[hand]) | |
# Define the judge function | |
def judge(player,computer): | |
# Add control flow based on the comparison of player and computer | |
if player==computer: | |
return 'Draw' | |
# used wrong else if statement | |
elif (player==0 and computer==1) or (player==1 and computer==2) or (player==2 and computer==0): | |
return 'Lose' | |
# Indentation of else was also off | |
else: | |
return 'Win' | |
print('Starting the Rock Paper Scissors game!') | |
player_name = input('Please enter your name: ') | |
print('Pick a hand: (0: Rock, 1: Paper, 2: Scissors)') | |
player_hand = int(input('Please enter a number (0-2): ')) | |
if validate(player_hand): | |
computer_hand = 1 | |
print_hand(player_hand, player_name) | |
print_hand(computer_hand, 'Computer') | |
# Assign the return value of judge to the result variable | |
result=judge(player_hand,computer_hand) | |
# Print the result variable | |
print('Result: ' + result) | |
else: | |
print('Please enter a valid number') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So this is the code you sent me. Let's break this down bit by bit.
elif
instead. So should have it asSo looking at your code, it should be like this at the end.