Read three whole numbers and print the largest. Solve it with if, without max().
What to build
A program that finds the largest value by comparing.
Requirements
- Read three whole numbers.
- Print the largest, using
ifrather thanmax().
Input
Three lines, each with one whole number.
Output
The largest of the three.
Constraints
The numbers may be equal, or negative.
Example
Input:
3
9
4
Output:
9
Why it works
Keeping the best value so far and comparing each new value with it works for any number of values, and handles ties correctly.
Examples
Example 1 · Input
3 9 4
Expected output
9
Example 2 · Input
-1 -5 -2
Expected output
-1
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Start with biggest = a, then compare b and c with it.
Solution
Show one correct solution (try it yourself first)
a = int(input())
b = int(input())
c = int(input())
biggest = a
if b > biggest:
biggest = b
if c > biggest:
biggest = c
print(biggest)