Python program to find the largest of three numbers
Description: Write a Python program to find the largest of three numbers.
Rules and hints:
- First use
if,elifandelse. - Then try the built-in
max()function.
Python program to find the largest of three numbers
a = 25
b = 78
c = 42
if a >= b and a >= c:
largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c
print("Largest number is", largest)
print("Using max():", max(a, b, c))
Output:
Tutorials Class - Output Window
Largest number is 78
Using max(): 78
How it works
- The first condition checks if
ais bigger than or equal to both others. - If not, the
elifchecksb. If both fail,cmust be the largest. max()does all this work in one call, so use it in real programs.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |