EXERCISE :6 SNAKE, WATER, GUN
"""
Exercise 6: Game Development: Snake Water Gun
Today's task for you guys will be to develop your first-ever Python game i.e., "Snake Water Gun."
Most of you must already be familiar with the game. Still, I will provide you with a brief description.
This is a two-player game where each player chooses one object. As we know, there are three objects, snake, water, and gun. So, the result will be
Snake vs. Water: Snake drinks the water hence wins.
Water vs. Gun: The gun will drown in water, hence a point for water
Gun vs. Snake: Gun will kill the snake and win.
In situations where both players choose the same object, the result will be a draw.
Now moving on to instructions:
You have to use a random choice function that we studied in tutorial #38, to select between, snake, water, and gun.
You do not have to use a print statement in case of the above function.
Then you have to give input from your side.
After getting ten consecutive inputs, the computer will show the result based on each iteration.
You have to use loops(while loop is preferred).
"""
import random
print("\n ********** WELCOME TO SNAKE || WATER || GUN ************\n")
n=int(input("Enter how many games you want to play : \n")) # 5
list1=["Snake", "Water", "Gun"]
d1={1:"Snake",2:"Water",3:"Gun"}
p_score=0 # Player Score
c_score=0 # Computer Score
while(n>0):
print("\nEnter your choice :\nPress 1 for Snake \nPress 2 for Water \nPress 3 for Gun")
a=int(input())
comp=random.choice(list1)
if(a==1): # Snake
if(comp=="Snake"):
print("\nYour choice : ",d1[1])
print("Computer choice : ",comp)
print("Tie !!")
elif(comp=="Gun"):
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("You loose... Computer won !!")
c_score=c_score+1
else:
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("You Won !!")
p_score=p_score+1
elif (a == 2): # Water
if (comp == "Snake"):
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("You Won !!")
p_score = p_score + 1
elif (comp == "Water"):
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("Tie !!")
else:
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("You loose... Computer won !!")
c_score = c_score + 1
elif (a == 3): # Gun
if (comp == "Water"):
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("You loose... Computer won !!")
c_score = c_score + 1
elif (comp == "Snake"):
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("You Won !!")
p_score = p_score + 1
else:
print("\nYour choice : ", d1[1])
print("Computer choice : ", comp)
print("Tie !!")
else:
print("YOU ENTERED WRONG CREDENTIALS.. PLEASE RUN THE PROGRAM AGAIN TO PLAY !!")
continue
n=n-1 # for reducing the chances
print("\n\n")
print("Your score : ",p_score)
print("Computer Score : ",c_score)
print("\n")
if p_score>c_score:
print(" ************* CONGRATULATIONS !! You won maximum rounds ***************")
elif c_score>p_score:
print(" ********** HARD LUCK !! System won maximum rounds ************")
else:
print(" **************** DRAW !! ******************")
Comments
Post a Comment