-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock-paper-scissors.py
68 lines (59 loc) · 1.59 KB
/
rock-paper-scissors.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import random
import time
def name_to_number(name):
if name == "rock":
number = 0
elif name == "spock":
number = 1
elif name == "paper":
number = 2
elif name == "lizard":
number = 3
else:
number = 4
return number
#assign number to given name
def number_to_name(number):
if number == 0:
name = "rock"
elif number == 1:
name = "spock"
elif number == 2:
name = "paper"
elif number == 3:
name = "lizard"
else:
name = "scissors"
return name
def rpsls():
print("battle started",end=" ")
for i in range(0,5):
print("->",end="")
time.sleep(.4)
print("\nchoose your choice: [rock / spock / paper / lizard / scissors]")
player_choice=input("Enter your choice here:")
player=name_to_number(player_choice)
computer = random.randrange(0,5)
print("you choose ",end="")
for i in range(0,5):
print(".",end=" ")
time.sleep(.3)
print(player_choice)
print("computer choose ",end="")
for i in range(0,5):
print(".",end=" ")
time.sleep(.3)
print(number_to_name(computer))
print("result is ",end="")
for i in range(0,5):
print(".",end=" ")
time.sleep(.5)
sel=(player-computer)%5
if sel==2 or sel==1:
print("congratulations: you won !!!")
elif sel==3 or sel==4:
print("sorry!! better luck next time : computer won")
else:
print("don't be upset ~~ : you tied with computer")
#calling the function
rpsls()