In a modify task you take code that already works and adapt it so that it does something else.
The editor starts you off with this number-guessing program:
number = 5
print("I have thought of a number between 1 and 10")
print("Can you guess what it is?")
guess = int(input())
if guess < number:
print("Too Low!")
if guess > number:
print("Too High!")
It tells the user when a guess is too small and when it is too big, but it says nothing at all when the guess is right, and it never asks the user how they think they did.
Adapt the code so that it does three more things. Leave everything that is already there exactly as it is.
Bad luck!. Put this check after the two that are already there.print
followed by an input() on the next line, and store their answer in a
variable.yes, output Well done!. In every other case,
output Never mind!. Use one if with an else for this, so that exactly one
of the two messages is always output.Ask the new question with its own print, exactly as written:
Did you guess correctly?
The questions and the messages are all part of the checked output, and are checked exactly as they are written here, capital letters and exclamation marks included:
Can you guess what it is?
Too Low!
Too High!
Bad luck!
Did you guess correctly?
Well done!
Never mind!
The answer to the second question is compared with yes in small letters.
Comparing text is case sensitive, so an answer of Yes or YES does not match
and gets the Never mind! message. That is the correct behaviour here, and it is
tested.
A guess that is too small, from a user who admits it:
Input:
2
no
Output:
I have thought of a number between 1 and 10
Can you guess what it is?
Too Low!
Bad luck!
Did you guess correctly?
Never mind!
A correct guess:
Input:
5
yes
Output:
I have thought of a number between 1 and 10
Can you guess what it is?
Did you guess correctly?
Well done!
The second output is shorter because a correct guess is neither too low nor too high nor unequal to the number, so all three of those branches are skipped.
Make sure that you check for the following things:
:) at the end of every if line and every else line.else.==) in a condition that checks whether
two pieces of data are the same, and != to check that they are different. A
single = stores data in a variable.input, and the second closing bracket
that int(input()) needs.int().