-
Notifications
You must be signed in to change notification settings - Fork 0
/
RockPaperScissor.py
44 lines (35 loc) · 1.02 KB
/
RockPaperScissor.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
import random
#Function to evaluate the choices
def game(comp, player):
if comp == player:
return None
if comp == "r" and player == "p":
return True
if comp == "p" and player == "s":
return True
if comp == "s" and player == "r":
return True
return False
#main
while True:
opt=['r', 'p', 's']
#comuter's choice
comp=random.choice(opt)
#player's choice
player = input("Enter your choice:- rock(r), paper(p) or scissor(s): ")
while player not in opt:
player=input("Please enter valid input:- rock(r), paper(p) or scissor(s): ")
#evaluate
x = game(comp, player)
#display of results
print("Computer chose: " +comp)
if x == None:
print("Its a Tie ")
elif x:
print("You won!!! :)")
else:
print("You lose :(")
#take user's consent to exit game
y=bool(input("Enter to continue else enter any letter to exit: "))
if y:
break