Python

Python program to Find Largest of three numbers

Python program to Find Largest of three numbers

In this article, we will discuss the concept of Python program to Find Largest of three numbers

In this post, we are going to learn how to write a program to find largest number out of three numbers using different methods in Python program.

Code to find largest numbers

Code to find largest numbers  using if statements

In this code, we will find largest number out of three numbers using if statements in Python language

Program 1

num1=76
num2=98
num3=45
#variable declaration and initilaization

if(num1>num2) and (num1>num3):
biggest=num1;

elif (num2>num1) and (num2>num3):
biggest=num2;

else:
biggest=num3;

print("The largest number is",biggest)
#display result on the screen

When the above code is executed, it produces the following result

The largest number is 98

 

Algorithm to find the greatest of three numbers using if-elif- else statements

  • Variable declaration and initialization
  • use an if-elif-else statements if(num1>num2) and (num1>num3), print num1
  • elif (num2>num1) and (num2>num3): print num2
  • Else  print num3
  • End of the program

 

Code to find largest numbers  using if elif statements – input from user

In this code, we will find largest number out of three numbers using if elif statements in Python language

Program 2

#Python program to find largest of three numbers
num1=int(input("Enter first number: "))
#reading the input value from user for num1
num2=int(input("Enter second number: "))
#reading the input value from user for num2
num3=int(input("Enter third number: "))
#reading the input value from user for num3

if(num1>num2) and (num1>num3):
    biggest=num1;

elif (num2>num1) and (num2>num3):
    biggest=num2;

else:
    biggest=num3;

print("The largest number is",biggest)
#display result on the screen

When the above code is executed, it produces the following result

Enter first number: 5678
Enter second number: 4325
Enter third number: 56747
The largest number is 56747

 

Algorithm to find the greatest of three numbers using if-elif- else statements

  • Get three input from the user
  • use an if-elif-else statements if(num1>num2) and (num1>num3), print num1
  • elif (num2>num1) and (num2>num3): print num2
  • Else  print num3
  • End of the program

 

Code to find largest numbers  using function

In this code, we will find largest number out of three numbers using function in Python language

Program 3

#Python program to find largest of three numbers
num1=int(input("Enter the first number: "));
num2=int(input("Enter the second number: "));
num3=int(input("Enter the Third number: "));
#reading the input from the user
def find_Largest():#method definition
     if(num1>=num2) and (num1>=num3):
         largest=num1
     elif(num2>=num1) and (num2>=num3):
         largest=num2
     else:
         largest=num3

     print("Largest number is",largest)

find_Largest();#Calling the method

When the above code is executed, it produces the following result

Enter the first number: 978
Enter the second number: 345
Enter the Third number: 654
Largest number is 978

 

Algorithm to find the greatest of three numbers using using function

  • Get three input from the user
  • define the function for find largest of three
  • Calling the function for display result
  • End of the program

 

Code to find largest numbers  using function – input from user

In this code, we will find largest number out of three numbers using function in Python language

Program 4

#Python program to find largest of three numbers
def find_Largest(num1,num2,num3):#method definition
     if(num1>=num2) and (num1>=num3):
         largest=num1
     elif(num2>=num1) and (num2>=num3):
         largest=num2
     else:
         largest=num3
     return largest
print("Enter three numbers")
num1=int(input());
num2=int(input());
num3=int(input());


print(find_Largest(num1,num2,num3))

 

When the above code is executed, it produces the following result

Enter three numbers
567
234
1022
1022

 

Suggested post

Operator in Python language

Data types in Python language

If statements in Python language

Nested if statement in Python language

 

Similar post

Java program to find middle of three

C program to find middle of three

C++ program to find middle of three

Python program to find middle of three

 

Java program to Find largest of three numbers

C program to Find largest of three numbers

C++ program to Find largest of three numbers

Python program to Find largest of three numbers

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.