Guess the number

Guess the number

What number am I thinking of?

A simple guessing game for young children asks the child to guess the number the computer has chosen at random. The child keeps guessing until they guess correctly.

Make


Write a program that generate a random number and asks the user to guess the number, outputting whether the guess is correct, too high or too low. The program should also output the number of guesses taken once the number has been guessed correctly.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called `play_guess_the_number` that:

  1. It chooses a random number between a minimum and maximum value (the computer’s choice).
  2. Asks the user to enter a guess.
  3. If the guess is too low it outputs, “Your guess is too low.”
  4. If the guess is too high it outputs, “Your guess is too high.”
  5. Repeats from step 2 until the user guesses correctly.
  6. Outputs a message to inform the user the game has ended including how many guesses they took.

Complete the `main program` so that:

  1. The user can input the minimum number for the computer to choose.
  2. The user can input the maximum number for the computer to choose.
  3. It outputs a message to start the game.

Typical inputs and outputs from the program would be:

What is the lowest number I can choose? :1

What is the highest number I can choose? :10

OK, let’s play. How many guesses will you take?

Enter the number I’m thinking of: 5

Your guess is too low.

Enter the number I’m thinking of: 7

You’ve got it, I chose 7. It took you 2 guesses.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


Run your program several times to check that your program has met the success criteria.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.
Craig'n'Dave logo

Craig ‘n’ Dave

Bett Awards 2024 Finalist