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)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay