DEV Community

Asim Shrestha
Asim Shrestha

Posted on

Guess the number

from random import randint

secret_number = randint(0, 10)  # guess number between 0 to 10 (including)
guess_count = 0

try:
    while True:
        user_number = int(input('Guess the number: '))
        guess_count += 1

        if user_number == secret_number:
            print('Correct')
            print('Your guess count:', guess_count)
            break
        elif user_number > secret_number:
            print('Your number is greater than the secret number.')
            continue
        elif user_number < secret_number:
            print('Your number is less than the secret number.')
            continue
        else:
            print('Invalid')
except ValueError:
    print('Please enter integer only.')

Enter fullscreen mode Exit fullscreen mode

Top comments (0)