In a make task you use the skills you have learned to create a program from scratch. There is no starter code: you begin with an empty editor.
You are going to write a guessing game in which the computer thinks of a number and the user has to find it.
Write a program that:
Some details, so that your game can be checked automatically:
random.randint(1, 100), once, at the start of the
program.I am thinking of a number between 1 and 100. once, before the first
guess.What is your guess?, and read the answer with a bare input().Your guess is too low or
Your guess is too high, and then ask again.Well done! and then
Number of guesses: NUMBER, where NUMBER counts every guess including the
right one.The opening line, then for every wrong guess the question followed by one message, then the question for the right guess, and finally the two lines at the end:
I am thinking of a number between 1 and 100.
What is your guess?
Your guess is too low
What is your guess?
Well done!
Number of guesses: 2
These examples show what happens when the number is 42 in the first run and 60 in the second. Your program will think of different numbers when you run it yourself.
Input:
50
25
37
43
40
42
Output:
I am thinking of a number between 1 and 100.
What is your guess?
Your guess is too high
What is your guess?
Your guess is too low
What is your guess?
Your guess is too low
What is your guess?
Your guess is too high
What is your guess?
Your guess is too low
What is your guess?
Well done!
Number of guesses: 6
Input:
60
Output:
I am thinking of a number between 1 and 100.
What is your guess?
Well done!
Number of guesses: 1
The checks fix the random seed before your program runs, so they know the
number in advance and can type in guesses that eventually hit it. That only
works if your program calls random.randint(1, 100) once, before the first
guess. Any other call that picks from the same numbers,
random.randrange(1, 101) for example, picks the same number and is fine too.
Ask each question with its own print, and read the answer with a bare
input() on the next line, rather than passing the question to input(...).
The questions are part of the output that is checked here, so their spelling,
capital letters and punctuation count.
Make sure that you check for the following things:
import random is the first line of the program.random.randint(1, 100) includes both 1 and 100.!=), and
the guess has a value before the loop starts that can never be the number.input() are both inside the loop.int(), or it is text and never equal to the
number.Well done! and the number of guesses are printed once, after the loop.