a python guessing game

Date:

Tags: coding · python · stem
Categories: python · coding

A Guessing Game


This is the code written by one of our students for a project during our 2025 summer camp.


import random
secret_number = random.randint(1, 1000)
attempts = 0

while True:
        try:

            guess = int(input("Enter your guess number between 1-1000: "))
            attempts += 1

            if guess < secret_number:
                print("Too low! ")
            elif guess > secret_number:
                print("Too high! ")
            else:
                print("Congratulations! You guessed it in " + str (attempts) + " attempts")
                print('\n')
                print("Let's play again.")
                print('\n')
                continue

        except ValueError:
            print("Please enter a valid number.")

This is how it would run: