Created
May 6, 2020 13:41
-
-
Save saipraveenkondapalli/6ed6291cd2e0746006bae0323759f561 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
import random | |
print('''Winning Rules as follows : | |
Rock vs paper-> paper wins | |
Rock vs scissor-> Rock wins | |
paper vs scissor-> scissor wins. | |
''') | |
def user(): | |
a = str() | |
while True: | |
try: | |
a = int(input("Enter Choice: ")) | |
break | |
except ValueError or a > 3 or a < 1: | |
print("enter valid input") | |
return a | |
def choice_name(cho): | |
if cho == 1: | |
player_name = 'rock' | |
elif cho == 2: | |
player_name = 'paper' | |
else: | |
player_name = "scissors" | |
return player_name | |
def com_choice(computer_choice): | |
if computer_choice == 1: | |
com_name = 'rock' | |
elif computer_choice == 2: | |
com_name = 'paper' | |
else: | |
com_name = 'scissors' | |
return com_name | |
def winner(cho, comp, play, cc): | |
if (cho == 1 and comp == 2) or (cho == 2 and comp == 1): | |
win = "paper" | |
elif (cho == 2 and comp == 3) or (cho == 3 and comp == 2): | |
win = "rock" | |
else: | |
win = "scissors" | |
if play == win: | |
print(f"you won") | |
elif cc == win: | |
print(f"computer wins \n") | |
else: | |
print("tie") | |
while True: | |
print("choice :\n 1.rock\n2.paper\n3.scissors") | |
choice = user() | |
player = choice_name(choice) | |
com = random.randint(1, 3) | |
computer = com_choice(com) | |
print(f"you choice is {player}") | |
print(f"computer choice is {computer}") | |
winner(com, choice, player, computer) | |
dec = input("do you want to play again[y or n]") | |
if dec.upper() == "N": | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment