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