-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from abhas20/abhas
added a game in python
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |