Write a Python Program to Find the Largest Among Three Numbers

When working with numerical data in Python, there are often times when we need to determine which value is the largest.

This is particularly useful when we have a set of data points and we need to identify the maximum value for further analysis.

In this tutorial, we will learn how to write a Python program to find the largest among three numbers.


To begin, let’s define the three numbers that we want to compare.

We can do this by assigning values to variables:

num1 = 10
num2 = 25
num3 = 15

Next, we need to compare these values to determine which one is the largest.

We can use a series of conditional statements to do this.

The basic structure of a conditional statement in Python is as follows:

if condition:
    # code to execute if condition is true
else:
    # code to execute if condition is false

Using this structure, we can compare the three numbers using the following code:

if (num1 >= num2) and (num1 >= num3):
    largest = num1
elif (num2 >= num1) and (num2 >= num3):
    largest = num2
else:
    largest = num3

This code uses a series of if and elif statements to compare each number to the others.

If the first number is greater than or equal to the second and third numbers, it is assigned as the largest value.

If the second number is greater than or equal to the first and third numbers, it is assigned as the largest value.

If neither of these conditions is true, then the third number must be the largest value.

Finally, we can print the result to the console using the print function:

print("The largest number is", largest)

Putting it all together, the complete code to find the largest among three numbers is as follows:

num1 = 10
num2 = 25
num3 = 15

if (num1 >= num2) and (num1 >= num3):
    largest = num1
elif (num2 >= num1) and (num2 >= num3):
    largest = num2
else:
    largest = num3

print("The largest number is", largest)

When we run this code, we should see the following output:

The largest number is 25

In summary, we can find the largest among three numbers in Python by comparing each number using a series of conditional statements.

By using the if, elif, and else statements, we can compare each number to the others and determine which one is the largest.

Once we have identified the largest number, we can print the result to the console using the print function.