Simple Python Games: Guess the Number

Source code of guess_the_number.py

from random import randint

limit_from = 0
limit_to = 10

print()
print("Guess the number from", limit_from, "to", limit_to, "! (Ctrl+C to exit)")
print()

the_number = randint(limit_from, limit_to)
guess = None

while the_number != guess:
    guess = input("Enter your guess: ")
    guess = int(guess)

    if guess < the_number:
        print("The number is bigger than", guess)
    if guess > the_number:
        print("The number is lower than", guess)
    print()

print("Yes! It's", the_number)
print()

Tips for improvement

  1. Handle the wrong (noninteger) input

Download

Source code of Guess the Number (guess_the_number.py).