Created
March 16, 2025 23:35
-
-
Save HandsonMatheus/5a8e03cb768fe6b8a48f804098def563 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