Unit 2 Task 15 - Solution

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Solution - Task 15: Higher–lower guessing game

← Back to task


One possible program:

import random

secret = random.randint(1, 100)
print("I'm thinking of a number from 1 to 100.")

while True:
    guess = int(input("Your guess: "))
    if guess < secret:
        print("Too low!")
    elif guess > secret:
        print("Too high!")
    else:
        print("Correct! Well done.")
        break