Python Program to Find Largest of 3 Numbers

In this post, we will learn how to find the largest of 3 numbers using Python Programming language.

This program takes three numbers as input from the user, and compares all three of them to find the largest number using the if. . .else statement.

So, without further ado, let’s begin this tutorial.

Python Program to Find Largest of 3 Numbers

# Python Program to Find Largest of 3 Numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))

# Finding largest number
if (num1 >= num2) and (num1 >= num3):
    largest = num1
elif (num2 >= num1) and (num2 >= num3):
    largest = num2
else:
    largest = num3
    
# Displaying output
print("Largest number is: ", largest)

Output

Enter first number: 22
Enter second number: 27
Enter third number: 21
Largest number is:  27

How Does This Program Work ?

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))

The user is asked to enter three integers.

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

Now, we compare whether num1 is greater than num2 and num3 or not. If the condition is true, then num1 is the largest number.

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

If the above condition is false, we check whether the value of num2 is greater than num1 and num3 or not. If yes, then num2 is the largest number.

else:
    largest = num3

If neither of the two conditions are true, then it clearly means num3 is the largest number.

# Displaying output
print("Largest number is: ", largest)

Finally, the largest number is displayed on the screen with the help of print() function.

Conclusion

I hope after going through this post, you understand how to find the largest of 3 numbers using Python Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to assist you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *