-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject_01.py
47 lines (38 loc) · 1.46 KB
/
Project_01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import random
# Function to determine winner
def determine_winner(player_choice, computer_choice):
if player_choice == computer_choice:
return "it's a tie!"
if (player_choice == "snake" and computer_choice == "water") or \
(player_choice == "water" and computer_choice == "gun") or \
(player_choice == "gun" and computer_choice == "sanke"):
return "You win!"
else:
return "Computer wins!"
# Function to get player's choice
def get_player_choice():
choices = ["snake", "water", "gun"]
while True:
player_choice = input("Enter your choice (snake,water,gun): ").lower()
if player_choice in choices:
return player_choice
else:
print("Invalid choice, plaease choose from snake,water,gun.")
# Function to get computer's choice.
def get_computer_choice():
choices = ["snake", "water", "gun"]
return random.choice(choices)
# Make function to play the game.
def play_game():
print("Welcome to the Snake,Water,Gun Game!")
# Get player and computer choices
player_choice = get_player_choice()
computer_choice = get_computer_choice()
print(f"Player's choice: {player_choice}")
print(f"Computer's choice: {computer_choice}")
# Determine the winner.
result = determine_winner(player_choice, computer_choice)
print(result)
# Run the game
if __name__ == "__main__":
play_game()