First, think of your favorite integer between 0 and 100. Write a program that stores your favorite number as a variable and repeatedly asks the user to try and guess it. Let the user know if their last guess was too low or too high.

For example, let's say your favorite number is 88. Here is a demo of a user trying to guess that number:

Try and guess my favorite number (between 0 and 100)
Guess: 50
Too low
Guess: 75
Too low
Guess: 87
Too low
Guess: 92
Too high
Guess: 90
Too high
Guess: 89
Too high
Guess: 88
Good job!

As an added bonus, try modifying the program to pick a different random favorite number each time.

Solution

"""
File: favorite_number.py
-------------------
This program prompts the user to guess its secret number and gives the user
hints until they guess it correctly.
"""

# The number the user must guess
FAVORITE_NUMBER = 88


def main():
    print("Try and guess my favorite number (between 0 and 100)")

    guess = int(input("Guess: "))
    while guess != FAVORITE_NUMBER:

        # Give them feedback on whether their guess was too low or too high
        if guess < FAVORITE_NUMBER:
            print("Too low")
        else:
            print("Too high")

        guess = int(input("Guess: "))

    print("Good job!")


if __name__ == '__main__':
    main()