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)

Quadratic: The AI-Powered Spreadsheet for Modern Teams cover image

Quadratic: The AI-Powered Spreadsheet for Modern Teams

Quadratic modernizes spreadsheets with AI integration, real-time collaboration, and support for SQL, Python, and JavaScript, offering a powerful, accessible data analysis tool without setup.

Read full post

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay