Created
January 31, 2022 15:43
-
-
Save Rmlyy/fbfd846edb0cfa911cf87c1658cccd50 to your computer and use it in GitHub Desktop.
Guessing game in Python
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
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