Using Python to Find The Largest Number Out Of Three

Beginners and expert developers can refer to this tutorial for learning How to find the largest number out of three using python. From here, you will easily understand the process of determining the largest number among three input numbers by using the explained different methods. Let’s get into this tutorial of Using Python to Find The Largest Number Out Of Three and check out the python programs to find the largest among three numbers with outputs.

The tutorial of determining the largest number out of three contains the following stuff: 

Python Program to Find Largest Among Three Numbers

Following is the useful snippet that will make you understand how to use Python to find the largest number out of any three given numbers. This snippet basically works on the if…elif…else statements to compare the three numbers against each other and returns which one is the largest. Look at the snippet below to understand how it works:

number1 = 33
number2 = 67
number3 = 51

if (number1 > number2) and (number1 > number3):
biggest = num1
elif (number2 > number1) and (number2 > number3):
biggest = number2
else:
biggest = number3

print("The biggest number between",number1,",",number2,"and",number3,"is",biggest)

In the illustration above, we know that num2 (67) is the biggest number. Therefore the second statement (the elif one) is the correct one because num2 is greater than both num1 and num3. Hence the final output would be like this:

“The biggest number between 33, 67, and 51 is 67.”

Do Check: 

Write a Program to Find the largest of Three Numbers in Python

If you want your users to be able to input the numbers themselves, simply insert these three lines in your code in place of the other num1, num2, and num3 declarations:

# Python program to find the largest of three numbers

# take inputs
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))
num3 = float(input('Enter third number: '))

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

# display result
print('The largest number = ', largest)

Output:

Enter first number: 7
Enter second number: 15
Enter third number: 4
The largest number = 15.0

or

Enter first number: 56
Enter second number: 90
Enter third number: 67
The largest number = 90

Largest among Three Numbers using max() Function

By using the following code, users can find the largest number of three numbers by the max() function. You can import this max() function from the library function. Look at the example:

# Python program to find the largest among 
# three numbers using max() function

# take inputs
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))
num3 = float(input('Enter third number: '))

# find largest numbers and display result
print('The largest number = ', max(num1, num2, num3))

Output: 

Enter first number: 15
Enter second number: 10
Enter third number: 19
The largest number = 19.0

Find The Largest Number Using List Function

In this approach, you have taken a list of all inputs and then called a max() method to return the largest number out of three. Check out the code below and understand how it works clearly:

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

my_list = [num1, num2, num3]
Largest = max(my_list)
print("The Largest number is", Largest)

Result:

Enter first number: 3
Enter second number: 6
Enter third number: 9
The Largest number is 9.0

Recommended Reading On: Python Program to Generate 26 Text Files named A.txt, B.txt, and so on up to Z.txt

Leave a Reply

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