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 a program that asks for two numbers and reports which of them is bigger:
print("Please enter a number")
number1 = int(input())
print("Please enter another number")
number2 = int(input())
if number1 > number2:
print("Number 1 is bigger than number 2")
elif number2 > number1:
print("Number 2 is bigger than number 1")
else:
print("Both numbers are the same")
Adapt the code so that it works with three numbers instead of two.
print followed
by an input() on the next line, exactly like the two questions that are
already there. It has to come after those two questions, so that the
three numbers arrive in the order first, second, third. Cast the answer with
int() the same way the other two lines do.if / elif / else statement that compares the third number
with the first one.if / elif / else statement that compares the third number
with the second one.Ask the new question with its own print, exactly as written:
Please enter a third number
Your program prints the three questions, in the order they are asked, followed by three result lines, one from each selection statement.
The three questions are these, the first two already printed by the starter code and the third the one you add:
Please enter a number
Please enter another number
Please enter a third number
The first result line is the one the starter code already prints, one of:
Number 1 is bigger than number 2
Number 2 is bigger than number 1
Both numbers are the same
The second result line reports the third number against the first, and must be worded exactly like this:
Number 3 is bigger than number 1
Number 3 is smaller than number 1
Number 3 is the same as number 1
The third result line reports the third number against the second, and must be worded exactly like this:
Number 3 is bigger than number 2
Number 3 is smaller than number 2
Number 3 is the same as number 2
All three questions and all three result lines are part of the checked output.
Input:
3
7
9
Output:
Please enter a number
Please enter another number
Please enter a third number
Number 2 is bigger than number 1
Number 3 is bigger than number 1
Number 3 is bigger than number 2
Input:
6
2
6
Output:
Please enter a number
Please enter another number
Please enter a third number
Number 1 is bigger than number 2
Number 3 is the same as number 1
Number 3 is bigger than number 2
Input:
5
5
5
Output:
Please enter a number
Please enter another number
Please enter a third number
Both numbers are the same
Number 3 is the same as number 1
Number 3 is the same as number 2
Make sure that you check for the following things:
if, has as many elif branches in the middle as you
need, and ends with else.if, elif and else line.if, elif and else lines themselves are not indented.if and each elif.else.==) in a condition that checks whether
two pieces of data are the same. A single = stores data in a variable.input is wrapped in int(), or the numbers are compared as text.