Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 45ad690

Browse files
committed
Added Snake,water and Gun game
1 parent 8c96f0f commit 45ad690

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

‎S/Snake,Water and Gun/main.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#rules
2+
# s= snake, w=water, g=gun
3+
# gun kills snake
4+
# gun sinks in water
5+
# snake drinks water
6+
7+
import random #exteral module
8+
9+
10+
def game(comp,you):
11+
if comp==you:
12+
return None
13+
elif comp=='s':
14+
if you=='w': # snake drinks water
15+
return False
16+
if you=='g': # gun kills snake
17+
return True
18+
elif comp=='w':
19+
if you=='g': # gun sinks in water
20+
return False
21+
if you=='s': # snake drinks water
22+
return True
23+
elif comp=='g':
24+
if you=='s': # gun kills snake
25+
return False
26+
if you=='w': # gun sinks in water
27+
return True
28+
29+
30+
31+
32+
print("Computer: Snake(s), Water(w) or Gun(g)?")
33+
rand= random.randint(1,3) #this function randomly chooses between numbers ranging from 1 to 3
34+
if rand==1:
35+
comp='s'
36+
elif rand==2:
37+
comp='w'
38+
elif rand==3:
39+
comp='g'
40+
print("Computer has Chosen")
41+
you= input("Player: Snake(s), Water(w) or Gun(g)?\n")
42+
result= game(comp,you)
43+
44+
if result==True:
45+
print("You Won!")
46+
print("Your Choice:",you)
47+
print("Computer's Choice:",comp)
48+
elif result==False:
49+
print("You Lose!")
50+
print("Your Choice:",you)
51+
print("Computer's Choice:",comp)
52+
elif result is None:
53+
print("Tie!")
54+
print("Your Choice:",you)
55+
print("Computer's Choice:",comp)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /