Skip to content

Commit

Permalink
Merge pull request #51 from sumant7/main
Browse files Browse the repository at this point in the history
Added Snake,Water and Gun game in Python
  • Loading branch information
Ayu-hack authored Oct 3, 2024
2 parents 0e23c2c + 53090a4 commit e7841f1
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions snakewatergun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#rules
# s= snake, w=water, g=gun
# gun kills snake
# gun sinks in water
# snake drinks water

import random #exteral module


def game(comp,you):
if comp==you:
return None
elif comp=='s':
if you=='w': # snake drinks water
return False
if you=='g': # gun kills snake
return True
elif comp=='w':
if you=='g': # gun sinks in water
return False
if you=='s': # snake drinks water
return True
elif comp=='g':
if you=='s': # gun kills snake
return False
if you=='w': # gun sinks in water
return True




print("Computer: Snake(s), Water(w) or Gun(g)?")
rand= random.randint(1,3) #this function randomly chooses between numbers ranging from 1 to 3
if rand==1:
comp='s'
elif rand==2:
comp='w'
elif rand==3:
comp='g'
print("Computer has Chosen")
you= input("Player: Snake(s), Water(w) or Gun(g)?\n")
result= game(comp,you)

if result==True:
print("You Won!")
print("Your Choice:",you)
print("Computer's Choice:",comp)
elif result==False:
print("You Lose!")
print("Your Choice:",you)
print("Computer's Choice:",comp)
elif result is None:
print("Tie!")
print("Your Choice:",you)
print("Computer's Choice:",comp)

0 comments on commit e7841f1

Please sign in to comment.