-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnake-Water-Gun-Game.py
60 lines (60 loc) · 1.77 KB
/
Snake-Water-Gun-Game.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
#Creating a game of snake, water and gun
import sys
import random
name=input("Enter your name:")
try:
t=int(input("How many turns you want to play: "))
except ValueError:
print("Invalid input. Please enter a valid integer.Rerun the program.")
sys.exit()
if(t>50 and t):
print("Limit Exceed!")
sys.exit()
print("Let's Play:-)")
options=['S','W','G']
choice={
'S':'Snake',
'W':'Water',
'G':'Gun'
}
cScore=uScore=0
i=0
while(i<t):
uChoice=input("Choose 'S' for snake, 'W' for water and 'G' for gun: ").upper()
cChoice=random.choice(options)
if(uChoice not in options):
print("Invalid choice.")
continue
elif(uChoice==cChoice):
print(f"You have chosen {choice[uChoice]} and Computer has chosen {choice[cChoice]}.")
print("It's a draw")
else:
print(f"You have chosen {choice[uChoice]} and Computer has chosen {choice[cChoice]}.")
if(cChoice=='S' and uChoice=='W'):
cScore+=1
print("Computer Won!")
elif(cChoice=='S' and uChoice=='G'):
uScore+=1
print("You Won!")
elif(cChoice=='W' and uChoice=='S'):
uScore+=1
print("You Won!")
elif(cChoice=='W' and uChoice=='G'):
cScore+=1
print("Computer Won!")
elif(cChoice=='G' and uChoice=='S'):
cScore+=1
print("Computer Won!")
elif(cChoice=='G' and uChoice=='W'):
uScore+=1
print("You Won!")
print(f"Computer Score\t|\t{name} Score")
print(f"\t{cScore}\t|\t\t{uScore}")
i+=1
if(uScore>cScore):
print("Congratulations! You won this game.")
elif(uScore<cScore):
print("Computer won! Better luck next time.")
else:
print("Match Tied!")
print("Game Over")