Created
May 12, 2017 13:52
-
-
Save odanga94/f2d6b784916f970f292bb0473afc34ba to your computer and use it in GitHub Desktop.
PracticePython/Exercise8(rock, paper, scissors cmd line)
This file contains hidden or 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_input(player_choice): | |
if player_choice != "r" and player_choice != "p" and\ | |
player_choice != "s": | |
print("The input was invalid. Please input 'r', 'p' or 's'") | |
return False | |
else: | |
return True | |
def winner(player_1_choice, player_2_choice): | |
if player_1_choice == player_2_choice: | |
print("it is a tie") | |
elif player_1_choice == "r" and player_2_choice == "s" or\ | |
player_1_choice == "p" and player_2_choice == "r" or\ | |
player_1_choice == "s" and player_2_choice == "p": | |
print("Player 1 wins this round") | |
else: | |
print("Player 2 wins this round") | |
def play(): | |
while True: | |
play = raw_input("play rock, paper, scissors?(y/n)") | |
if play == "y": | |
player_1_choice = raw_input("Player 1, enter r, p or s:") | |
if validate_input(player_1_choice) == True: | |
player_2_choice = raw_input("Player 2, enter r, p or s:") | |
if validate_input(player_2_choice) == True: | |
winner(player_1_choice, player_2_choice) | |
else: | |
continue | |
elif play == "n": | |
return | |
else: | |
print("Invalid response. Only 'y' or 'n' are allowed") | |
play() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment