-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame coding.py
More file actions
59 lines (46 loc) · 1.64 KB
/
Game coding.py
File metadata and controls
59 lines (46 loc) · 1.64 KB
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
import random
print('Winning rules of the game ROCK PAPER SCISSORS are:\n'
+ "Rock vs Paper -> Paper wins \n"
+ "Rock vs Scissors -> Rock wins \n"
+ "Paper vs Scissors -> 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 please : '))
if choice == 1:
choice_name = 'Rock'
elif choice == 2:
choice_name = 'Paper'
else:
choice_name = 'Scissors'
print('User choice is:', choice_name)
print("Now it's Computer's Turn...")
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 = 'Scissors'
print("Computer choice is:", comp_choice_name)
print(choice_name, 'vs', comp_choice_name)
if choice == comp_choice:
result = "DRAW"
elif (choice == 1 and comp_choice == 2) or (comp_choice == 1 and choice == 2):
result = 'Paper'
elif (choice == 1 and comp_choice == 3) or (comp_choice == 1 and choice == 3):
result = 'Rock'
elif (choice == 2 and comp_choice == 3) or (comp_choice == 2 and choice == 3):
result = 'Scissors'
if result == "DRAW":
print("<== It's a tie! ==>")
elif result == choice_name:
print("<== User wins! ==>")
else:
print("<== Computer wins! ==>")
print("Do you want to play again? (Y/N)")
ans = input().lower()
if ans == 'n':
break
print("Thanks for playing!")