Skip to content

Commit

Permalink
Merge pull request #254 from abhas20/abhas
Browse files Browse the repository at this point in the history
added a game in python
  • Loading branch information
AkhzarFarhan authored Oct 23, 2024
2 parents a783d27 + 7ef162c commit d216043
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Python/game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import random

def play_game():
choices = ["snake", "water", "gun"]
user_choice = input("Enter your choice (snake/water/gun): ").lower()
computer_choice = random.choice(choices)

print(f"Computer chose: {computer_choice}")

if user_choice == computer_choice:
print("It's a tie!")
elif user_choice == "snake":
if computer_choice == "water":
print("You win! Snake drinks water.")
else:
print("You lose! Gun shoots snake.")
elif user_choice == "water":
if computer_choice == "gun":
print("You win! Water rusts the gun.")
else:
print("You lose! Snake drinks water.")
elif user_choice == "gun":
if computer_choice == "snake":
print("You win! Gun shoots snake.")
else:
print("You lose! Water rusts the gun.")
else:
print("Invalid input. Please choose snake, water, or gun.")

play_game()

0 comments on commit d216043

Please sign in to comment.