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, elif and else.
  • 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 a is bigger than or equal to both others.
  • If not, the elif checks b. If both fail, c must 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.