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.
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
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
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…