forked from theutpal01/HacktoberFest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock_paper_scissor.py
44 lines (35 loc) · 1.04 KB
/
rock_paper_scissor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# rock -> scissor
# scissor -> paper
# paper -> rock
import random
def game(comp, you):
if comp==you:
return None
elif ((comp == "r" and you == "s")or(comp == "s" and you == "p")or(comp == "p" and you == "r")):
return False
else:
return True
while(1):
r = random.randint(1,3)
if (r == 1):
comp = "r"
elif (r == 2):
comp = "p"
elif (r == 3):
comp = "s"
print("Enter r for Rock, p for Paper and s for Scissor")
you = input()
result = game(comp,you)
if (result == None):
print(f"Game is tie.\nComputer choose {comp} and you choose {you}")
elif (result == True):
print(f"Congratulations! You are winner.\nComputer choose {comp} and you choose {you}")
elif (result == False):
print(f"You lose. Computer wins.\nComputer choose {comp} and you choose {you}")
print("Do you want to play again?(y/n)")
choice = input()
if choice == 'y':
continue
elif choice == 'n':
print("Thanks for visiting")
break