Last active
April 20, 2019 13:43
-
-
Save JagDecoded/c399f64ff9f996d9a95e8aea67e2e55d to your computer and use it in GitHub Desktop.
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
# Thank you ManyInterests(and reddit community) for suggestion and improving me. reddit link https://redd.it/6hu6k9 | |
def rps_winner(p1_move,p2_move,player1_name,player2_name): | |
a= 'rock' | |
b= 'scissors' | |
c= 'paper' | |
if p1_move==p2_move: | |
print("tie") | |
elif (p1_move==a and p2_move==b) or (p1_move==b and p2_move==c) or (p1_move==c and p2_move==a): | |
print("%s won" %player1_name) | |
else: | |
print("%s won" %player2_name) | |
def ask_for_move(player_name): | |
valid_choices= ['rock','paper','scissors'] | |
player_move=input("%s choose from rock, paper or scissors: " %player_name).lower() | |
while True: | |
if player_move not in valid_choices: | |
player_move=input("Wrong entry, Try again from rock, paper or scissors: ").lower() | |
else: | |
return player_move | |
def game_loop(): | |
player1_name= input("Player 1 enter your name: ") | |
player2_name= input("Player 2 enter your name: ") | |
keep_playing= 'y' | |
while keep_playing=='y': | |
player1_move= ask_for_move(player1_name) | |
player2_move= ask_for_move(player2_name) | |
rps_winner(player1_move,player2_move,player1_name,player2_name) | |
keep_playing= input("do you want to continue??? type y to continue: ").lower() | |
if keep_playing=='y': | |
continue | |
else: | |
print("thank you for playing:)") | |
break | |
game_loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First Copy Watches in India