File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ # Snake-Water-Game
2+
3+
4+ ![ Screenshot (83)] ( https://user-images.githubusercontent.com/101285245/201472214-de346df8-bd26-4af2-bfe5-d1c7516ce29f.png )
Original file line number Diff line number Diff line change 1+ from ctypes .wintypes import PINT
2+ from math import gamma
3+ from pickle import TRUE
4+ import random
5+ from tkinter .tix import Tree
6+
7+
8+ def game (comp ,mine ):
9+ if (comp == mine ):
10+ return None
11+ if (comp == 'snake' and mine == 'gun' ):
12+ return True
13+ elif (comp == 'water' and mine == 'snake' ):
14+ return True
15+ elif (comp == 'gun' and mine == 'water' ):
16+ return True
17+ else :
18+ return False
19+
20+ # Here is the main code started... #
21+
22+ choice = ('snake' ,'water' ,'gun' )
23+ # choice is tuple and it will not change in future
24+ comp = random .randint (0 ,2 )
25+ comp = choice [comp ]
26+ # choosing one comp if user pick the value like
27+ # 0-snake
28+ # 1-water
29+ # 2-gun
30+ # 3-invalid input
31+ mine = input ('Your input:' )
32+ if (mine == 'snake' or mine == 'gun' or mine == 'water' ):
33+ WinTheGame = game (comp ,mine )
34+ else :
35+ WinTheGame = - 1
36+ print (f"You choose { mine } and the computer choose { comp } " )
37+ if WinTheGame == - 1 :
38+ print ('Invalid input.' )
39+ elif WinTheGame is None :
40+ print ('Match is drawn.' )
41+ elif WinTheGame :
42+ print ("You Won." )
43+ else :
44+ print ("You Lose." )
You can’t perform that action at this time.
0 commit comments