Snake, Water and Gun game in python
here ,
we are going to make a console game in python. This is a very interesting game that we were play in our childhood.
The code of game is given below:
import random
# Snake Water Gun or Rock Paper Scissors
def gameWin(comp, you):
# If two values are equal, declare a tie!
if comp == you:
return None
# Check for all possibilities when computer chose s
elif comp == 's':
if you=='w':
return False
elif you=='g':
return True
# Check for all possibilities when computer chose w
elif comp == 'w':
if you=='g':
return False
elif you=='s':
return True
# Check for all possibilities when computer chose g
elif comp == 'g':
if you=='s':
return False
elif you=='w':
return True
print("Comp Turn: Snake(s) Water(w) or Gun(g)?")
randNo = random.randint(1, 3)
if randNo == 1:
comp = 's'
elif randNo == 2:
comp = 'w'
elif randNo == 3:
comp = 'g'
you = input("Your Turn: Snake(s) Water(w) or Gun(g)?")
a = gameWin(comp, you)
print(f"Computer chose {comp}")
print(f"You chose {you}")
if a == None:
print("The game is a tie!")
elif a:
print("You Win!")
else:
print("You Lose!")
Output of the program:
PS C:\Users\JORDAN> python -u "e:\pdf\AndroLua\Project 1\main.py"
Comp Turn: Snake(s) Water(w) or Gun(g)?
Your Turn: Snake(s) Water(w) or Gun(g)?w
Computer chose g
You chose w
You Win!
PS C:\Users\JORDAN>
Comments
Post a Comment