-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRock-Paper-Scissors-Lizard-Spock
46 lines (41 loc) · 1.01 KB
/
Rock-Paper-Scissors-Lizard-Spock
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
45
46
from random import randint
l=[0,1,2,3,4,5]
entity={0:"rock",1:"spock",2:"paper",3:"lizard",4:"scissors"}
def winner(x,y):
a,b=nextOf(x)
if y==a or y==b:
return 1
else:
return 0
def nextOf(x):
a=l[(x+1)%5]
b=l[(x+2)%5]
return a,b
def name_to_number(name):
x=[key for key,value in entity.items() if value == name]
return x[0]
def number_to_name(number):
return entity.get(number)
def rpsls(name):
us1=name.lower()
us2=number_to_name(randint(0,4))
print "Player choosed",us1
print "Computer choosed",us2
if name_to_number(us1)==name_to_number(us2):
win=2
else:
win=winner(name_to_number(us1),name_to_number(us2))
if win==0:
#print us1,"beats",us2
print"Player Wins!"
elif win==1:
#print us2,"beats",us1
print "Computer Wins!"
else:
print"Player and computer tie!"
print "--------------------------\n"
rpsls("rock")
rpsls("Spock")
rpsls("paper")
rpsls("lizard")
rpsls("scissors")