Created
March 16, 2025 17:59
-
-
Save HandsonMatheus/6cd4302494934f41ce096ea4afa37186 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import random | |
| secret_number = random.randint(1, 9) | |
| print("You have 5 tries to guess the secret number (1-9)") | |
| while True: | |
| try: | |
| player_guess = int(input("Type your guess >>> ")) | |
| if player_guess == secret_number: | |
| print("Right answer.") | |
| elif player_guess > secret_number: | |
| print(f"Too high.") | |
| continue | |
| else: | |
| print(f"Too low.") | |
| continue | |
| except ValueError: | |
| print("Wrong input.") | |
| # ASK IF THE USER WANTS TO PLAY IT AGAIN | |
| play_again = input(f"Play again? [y/n] >>> ").lower() | |
| if play_again != "y": | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment