import random def number_to_name number if number choisecomp rock elif

 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
47
48
49
50
51
52
53
import random
def number_to_name(number):
if number==0:
choisecomp="rock"
elif number==1:
choisecomp="spock"
elif number==2:
choisecomp="paper"
elif number==3:
choisecomp="lizard"
elif number==4:
choisecomp="scissors"
else:
choisecomp="wrongchoise"
return choisecomp
def name_to_number(name):
if name=="rock":
choiseplayer=0
elif name=="spock":
choiseplayer=1
elif name=="paper":
choiseplayer=2
elif name=="lizard":
choiseplayer=3
elif name=="scissors":
choiseplayer=4
else: choiseplayer=10
return choiseplayer
def rpsls(name):
if name_to_number(name)>5:
print "Player chooses", name, "it's wrong choise"
else:
print "Player chooses", name
number=random.randrange(0,5)
if number>5:
print "Computer chooses", number_to_name(number), "it's wrong choise"
else: print "Computer chooses", number_to_name(number)
winner=(number - name_to_number(name))%5
if winner==1 or winner==2:
print "Computer wins!"
else:
print "Player wins!"
rpsls("rock")
rpsls("spock")
rpsls("paper")
rpsls("lizard")
rpsls("scissors")