Python Exercise 7 --- "Snake, Water, Gun"
Python Exercise 7 --- "Snake, Water, Gun"
Today's task for you guys will be to develop your first-ever Python game i.e., "Snake Water Gun." (Just like --- Rock, Paper, Scissor)
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).
CODE ---
# Snake-Water-Gun Game
import random
list1 = ["S", "W", "G"]
chance = 10
no_of_chance = 0
computer_point = 0
human_point = 0
print("\t\t\t\tSnake-Water-Gun Game\n")
print("How To Play ------\n", "Press 's' for Snake \n Press 'w' for Water \n Press 'g' for Gun\n")
# Starting While Loop
while no_of_chance < chance:
inp = input("Choose any of them 'Snake, Water, Gun' --- ")
rand = random.choice(list1)
# Tie Function
if inp == rand:
print("This is TIE. Both got 0 points")
# If User enter S
if (inp. == "S") and (rand == "G"):
computer_point = computer_point + 1
print(f"Your guess is {inp} and Computer's guess is {rand}\n")
print("Computer gets +1, You got 0")
print(f"Your score is {human_point}\tComputer's score is {computer_point}")
elif (inp == "S") and (rand == "W"):
human_point = human_point + 1
print(f"Your guess is {inp} and Computer's guess is {rand}\n")
print("You get +1, Computer got 0")
print(f"Your score is {human_point}\tComputer's score is {computer_point}")
# If User enters W
if (inp == "w", "W") and (rand == "S"):
computer_point = computer_point + 1
print(f"Your guess is {inp} and Computer's guess is {rand}\n")
print("Computer gets +1, You got 0")
print(f"Your score is {human_point}\tComputer's score is {computer_point}")
elif (inp == "W") and (rand == "G"):
human_point = human_point + 1
print(f"Your guess is {inp} and Computer's guess is {rand}\n")
print("You get +1, Computer got 0")
print(f"Your score is {human_point}\tComputer's score is {computer_point}")
# If user enters G
if (inp == "G") and (rand == "W"):
computer_point = computer_point + 1
print(f"Your guess is {inp} and Computer's guess is {rand}\n")
print("Computer gets +1, You got 0")
print(f"Your score is {human_point}\tComputer's score is {computer_point}")
elif (inp == "G") and (rand == "S"):
human_point = human_point + 1
print(f"Your guess is {inp} and Computer's guess is {rand}\n")
print("You get +1, Computer got 0")
print(f"Your score is {human_point}\tComputer's score is {computer_point}")
# Chance
no_of_chance = no_of_chance + 1
print(f"{no_of_chance} is left out of {chance}")
print("GAME OVER")
# Winner Deciding
if computer_point == human_point:
print("Tie")
elif computer_point > human_point:
print("Computer wins and you loose")
else :
print("you win and computer loose")
print(f"Your Total Score is {human_point}\tand\tComputer's Total Score is {computer_point}")
Comments
Post a Comment