Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save HandsonMatheus/6cd4302494934f41ce096ea4afa37186 to your computer and use it in GitHub Desktop.

Select an option

Save HandsonMatheus/6cd4302494934f41ce096ea4afa37186 to your computer and use it in GitHub Desktop.
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