-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockPaperScissors.py
101 lines (63 loc) · 2.03 KB
/
rockPaperScissors.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import random
print(
" In order to win rock paper scissors the conditions are :\n"
+ "Rock vs Paper -> Paper wins \n"
+ "Rock vs Scissors -> Rock wins \n"
+ "Scissors vs Paper -> Scissors wins \n"
)
while True:
print("Enter your choice \n 1 - Rock \n 2 - Paper \n 3 - Scissors \n")
choice = int(input("Enter your Choice: "))
while choice > 3 or choice < 1:
choice = int(input("Enter a valid choice: "))
if choice == 1:
choice == "Rock"
elif choice == 2:
choice == "Paper"
elif choice == 3:
choice == "Scissor"
print("You chose ", choice)
print("Computer chose... ")
comp_choice = random.randint(1, 3)
while comp_choice == choice:
comp_choice = random.randint(1, 3)
if comp_choice == 1:
comp_choice_name = "Rock"
elif comp_choice == 2:
comp_choice_name = "Paper"
else:
comp_choice_name = "Scissor"
print("Computer = \n", comp_choice_name)
print(choice, "v", comp_choice_name)
if choice == comp_choice:
print("Drawn", end="")
result = "Draw"
if choice == 1 and comp_choice == 2:
print("paper wins => ", end="")
result = "Paper"
elif choice == 2 and comp_choice == 1:
print("paper wins => ", end="")
result = "Paper"
if choice == 1 and comp_choice == 3:
print("Rock wins => ", end="")
result = "Rock"
elif choice == 3 and comp_choice == 1:
print("Rock wins => ", end="")
result = "Rock"
if choice == 2 and comp_choice == 3:
print("Scissors wins => ", end="")
result = "Scissors"
elif choice == 3 and comp_choice == 2:
print("Scissors win => ", end="")
result = "Scissors"
if result == "Draw":
print("<== Both win ==>")
if result == choice:
print("<== User wins ==>")
else:
print("<== Computer wins ==>")
print("Play again? (Y/N)")
ans = input().lower
if ans == "n":
break
print("Thank you for playing.")