Contents

## Python – Find Largest of Three Numbers

To find the largest of three numbers, we could write a compound condition to check if a number is greater than other two.

### Example 1: Find Largest of Three Numbers using IF

In this example, we shall use simple Python If statement to find the largest of three numbers.

We shall follow these steps to find the largest number of three.

- Read first number to
**a**. - Read second number to
**b**. - Read third number to
**c**. - If
**a**is greater than**b**and**a**is greater than**c**, then**a**is the largest of the three numbers. - If
**b**is greater than**a**and**b**is greater than**c**, then**b**is the largest of the three numbers. - If
**c**is greater than**a**and**c**is greater than**b**, then**c**is the largest of the three numbers.

**Python Program**

```
a = int(input('Enter first number : '))
b = int(input('Enter second number : '))
c = int(input('Enter third number : '))
largest = 0
if a > b and a > c:
largest = a
if b > a and b > c:
largest = b
if c > a and c > b:
largest = c
print(largest, "is the largest of three numbers.")
```

**Output**

### Example 2: Find Largest of Three Numbers using IF-ELIF

In our previous example, we have written conditions to find the largest. But, these conditions are independent of each other. And we have not taken advantage that if **a** is not greater than either of **b** or **c**, then there is no use to check if **b** is greater than **a** or **c** is greater than **a**.

So, using elif statement, we shall take advantage of the dependency of conditions.

**Python Program**

```
a = int(input('Enter first number : '))
b = int(input('Enter second number : '))
c = int(input('Enter third number : '))
largest = 0
if a > b and a > c :
largest = a
elif b > c :
largest = b
else :
largest = c
print(largest, "is the largest of three numbers.")
```

**Output**

### Summary

In this tutorial of Python Examples, we learned how to find the largest of three numbers using conditional statements.

### Related Tutorials

- Python Program to Add Two Numbers
- Python – Sum of Two Numbers
- Python – Sum of First N Natural Numbers
- Numpy sqrt() – Find Square Root of Numbers
- Python – Smallest of Three Numbers
- How to Get Number of Axes in Pandas DataFrame?
- How to Swap Two Numbers in Python?
- Python – Factorial of a Number
- Python String – Find the number of overlapping occurrences of a substring
- Reverse a Number in Python