Skip to content

Instantly share code, notes, and snippets.

@Rmlyy
Created January 31, 2022 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rmlyy/fbfd846edb0cfa911cf87c1658cccd50 to your computer and use it in GitHub Desktop.
Save Rmlyy/fbfd846edb0cfa911cf87c1658cccd50 to your computer and use it in GitHub Desktop.
Guessing game in Python
from random import randint
min = 1
max = 10
number = randint(min, max)
tries = 1
while True:
print(f'Try {tries}')
answer = input(f'Guess the number between {min} and {max}: ')
if answer.isdigit():
answer = int(answer)
if answer != number:
tries += 1
print('Wrong. Try again')
else:
print(f'Congratulations, you guessed the correct number in {tries} tries.')
exit()
else:
print('Invalid number.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment