Python program to find largest number among three numbers
- Home
- Find elements
- Python program to find largest number among three numbers
- On
- By
- 0 Comment
- Categories: Find elements
Python program to find largest number among three numbers
Python program to find largest number among three numbers
In this tutorial, we will discuss the Python program to find largest number among three numbers.
This post explains how to find the largest number among three numbers using if statements with the operator in Python.
There are many ways to find the largest number among the three numbers in Python. but here, we use if elif statements and with the and operator.
Here, we provide two programs to find the largest number among the three numbers.
first program leads to find the largest number among three integer numbers.
Second program leads to find the largest number among three floating point numbers.
Find the largest number among three integer numbers
Program 1
num1=int(input("Enter the first number: ")) num2=int(input("Enter second number: ")) num3=int(input("Enter the third number: ")) #get input from user for num1,num2,num3 if(num1>num2) and (num1>num3): biggest=num1; #check whether the num1 is smaller than num2 and num3 elif (num2>num1) and (num2>num3): biggest=num2; #check whether the num2 is smaller than num1 and num3 else: biggest=num3; print("The largest number is",biggest);
When the above code is executed, it produces the following results
Enter the first number: 98 Enter second number: 65 Enter the third number: 43 The largest number is 98
This program takes input from the user for num1,num2, num3. then, this program finds and displays the largest number among the three integer numbers
Find the largest number among three floating point numbers
Program 2
num1=float(input("Enter the first number: ")) num2=float(input("Enter second number: ")) num3=float(input("Enter the third number: ")) #get input from user for num1,num2,num3 if(num1>num2) and (num1>num3): biggest=num1; #check whether num1 is smaller than num2 and num3 elif (num2>num1) and (num2>num3): biggest=num2; #check whether the num2 is smaller than num1 and num3 else: biggest=num3; print("The largest number is",biggest);
When the above code is executed, it produces the following results
Enter the first number: 23.65 Enter second number: 78.45 Enter the third number: 67.34 The largest number is 78.45
This program takes input from the user for num1,num2, num3. then, this program finds and displays the largest number among the three decimal numbers
Suggested for you
If statement in Python language