|
1 | 1 | import random |
2 | 2 |
|
| 3 | +choices = ["rock", "paper", "scissors", "lizard", "spock"] |
3 | 4 |
|
4 | 5 | def get_user_choice(): |
5 | | - choices = ["rock", "paper", "scissors", "lizard", "spock"] |
6 | 6 | user_choice = input("Enter your choice (rock, paper, scissors, lizard, spock): ").lower() |
7 | 7 | while user_choice not in choices: |
8 | 8 | user_choice = input("Invalid choice. Please enter rock, paper, scissors, lizard, or spock: ").lower() |
9 | 9 | return user_choice |
10 | 10 |
|
11 | 11 |
|
12 | 12 | def get_computer_choice(): |
13 | | - choices = ["rock", "paper", "scissors", "lizard", "spock"] |
14 | 13 | return random.choice(choices) |
15 | 14 |
|
16 | 15 |
|
@@ -76,12 +75,16 @@ def play_game(): |
76 | 75 | print(f"User: {user_score}") |
77 | 76 | print(f"Computer: {computer_score}") |
78 | 77 | print(f"Ties: {ties}") |
| 78 | + |
| 79 | + while True: |
| 80 | + play_again = input("\nDo you want to play again? (y/n): ").lower() |
| 81 | + if play_again in ["y", "n"]: |
| 82 | + break |
| 83 | + print("Invalid input. Please enter 'y' or 'n'.") |
79 | 84 |
|
80 | | - play_again = input("\nDo you want to play again? (y/n): ").lower() |
81 | 85 | if play_again != "y": |
82 | 86 | print("Thanks for playing!") |
83 | 87 | break |
84 | 88 |
|
85 | | - |
86 | 89 | if __name__ == "__main__": |
87 | 90 | play_game() |
0 commit comments