Python Program to Find Largest of Two Numbers

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

This program takes two numbers as input from the user and stores them in first and second named variables. Then, it finds the largest among them using the if. . .else statement.

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

Python Program to Find Largest of Two Numbers

# Python Program to Find Largest of Two Numbers
first = float(input("Enter first number: "))
second = float(input("Enter second number: "))

# Finding Largest of two
if first > second:
    largest = first
else:
    largest = second
    
# Displaying output
print("The largest number between {0} and {1} is: {2}" .format(first, second, largest))

Output

Enter first number: 48
Enter second number: 45
The largest number between 48.0 and 45.0 is: 48.0

How Does This Program Work ?

first = float(input("Enter first number: "))
second = float(input("Enter second number: "))

The user is asked to enter two numbers. The numbers are stored in the first and second named variables.

# Finding Largest of two
if first > second:
    largest = first
else:
    largest = second

Now, we use the if. . .else statement to compare which of the two numbers is greater.

# Displaying output
print("The largest number between {0} and {1} is: {2}" .format(first, second, largest))

The largest of two is printed on the screen using print() function.

Conclusion

I hope after going through this post, you understand how to find the largest of two 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 *