×

Python Program to Find the Greatest Among Three Numbers

Python Program to find the greatest among three numbers

We have many approaches to get the largest of three numbers, and here we will discuss a few of them. This python program needs the user to enter three numbers. Next, Python will compare these numbers and print the greatest among them.

Input: A = 4, B = 6, C = 8  Output: C is the greatest

Method 1: By using Python Elif Statement

#Program to find the greatest among three   
#Take three number from user to compare 
num1 = int(input("Enter first number: ")) 
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
#compare the number 
 if (num1 > num2 and num1 > num3): 
 print("{0} is Greater Than both {1} and {2}". format(num1, num2, num3)) 
elif (num2 > num1 and num2 > num3):           
print("{0} is Greater Than both {1} and {2}". format(num2, num1, num3)) 
elif (num3 > num1 and num3 > num2):          
 print("{0} is Greater Than both {1} and {2}". format(num3, num1, num2))
 else:      
#Print the result  
print("Either any two values or all the three values are equal")

Output

CASE 1:

greatest among three numbers

CASE 2:

greatest among three numbers

Explanation: In this program, a user will be asked to enter three numbers. This number will be stored in a separate variable. Now, we will compare all three numbers against each other using if...elif...else statement. After the comparison, the greatest among the three numbers will returns and prints on the screen.

Method 2: By using Nested If Statement

This program uses the nested IF statement to find the Largest of Three numbers in Python:

#Program to find the greatest among three     
 #Take three number from user to compare  num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: ")) 
num3 = int(input("Enter third number: ")) 
#compare the number 
 if (num1-num2 > 0) and (num1-num3 > 0):    
 print("{0} is Greater Than both {1} and {2}". format(num1, num2, num3)) 
else:    
 if(num2 - num3 > 0): 
print("{0} is Greater Than both {1} and {2}". format(num2, num1, num3))   
  else:       
  print("{0} is Greater Than both {1} and {2}". format(num3, num1, num2))

Output

Here is the output:

greatest among three numbers

Related Topics

Speech Recognition Module in Python

Speech Module in Python: Converting text to speech, known as Speech Synthesis, this process is the computer-generated recreation of human speech. This module converts the human language text into human-like...

8 minutes read.

Write a String in Python

Python is an object-oriented high-level programming language. Python has dynamic semantics and has high-level built-in data structures which support dynamic typing and dynamic binding. Python provides rapid development. It has...

5 minutes read.

Python md5_file() function

Python md5_file() function The md5_file() function in PHP calculates the md5 hash of a given file. Syntax md5_file ( string $filename [, bool $raw_output ] )  Parameter filename(required)- This parameter signifies the file to be calculated. raw_output(optional)- It takes a boolean value that specifies hex or binary...

1 minute read.

Gethostbyname() function in Python

Python Programming Language Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

6 minutes read.

Is Python Case-sensitive when Dealing with Identifiers

Yes, Python is a case-sensitive language while dealing with identifiers. Python is one of the top trending, widely-used programming languages. Python is a general-purpose programming language. It is a case-sensitive...

6 minutes read.

STL in Python

Python has many libraries that are very useful and simplify many complex codes. In the same way, STL is also one of the python libraries used for reading and writing...

3 minutes read.

Python MySQL Database Connection

In this article, you will be able to understand how to connect to a MySQL database through Python. We generally can use many methods or modules to connect to the database...

6 minutes read.

How to change the names of Columns in Python

Introduction To play with huge amounts of data, in Python we require a tool. The tool which is available in Python is Pandas. Pandas is an open-source library. It is used...

3 minutes read.

Important Difference between Python 2.x and Python 3.x with Example

The comparison between Python 2 and Python 3 is given in the article that follows. Python is a computer language that can perform more tasks than other languages and is...

5 minutes read.

any() Keyword in python

“any” keyword in python This page contains all the information about any () Keyword in python, how it is used with lists, tuples, dictionaries, sets, and what its function is? Python...

3 minutes read.

Difference Between Python and Scala

What is Python? Python is a high-level general-purpose interpreted programing language. It is used for multi general-purpose work such as language construct as well as its object-oriented approach aims to help...

4 minutes read.

Python Modulo

For basic calculations, Python provides operators. Python supports a broad range of Arithmetic Operators to do arithmetic, as given below: +Addition*Multiplication-Subtraction/Division//Floor division**Exponentiation%Remainder/Modulus As you can see, one of these basic arithmetic operators...

8 minutes read.

Python program to find the area of a circle

Python program to find the area of a circle This article will discuss how to find the area of a circle in Python with a given radius. The area of a...

2 minutes read.

Find Median of List in Python

The median is an enlightening measurement that is utilized as a proportion of the focal inclination of a circulation. It is equivalent to the centre worth of the conveyance. There...

3 minutes read.

How To Print Colored Text in Python

Changing the colour of certain parts of a string when printing the output of a Python programme to the terminal may make it easier to read. We can approach this...

3 minutes read.

Accessing Key-value in Dictionary in Python

A Python word reference is an assortment of key-esteem matches where each key is related to worth. Worth in the key-esteem pair can be a number, a string, a rundown,...

5 minutes read.

Python lock

Before understanding the concept of Python-lock we need to understand what kind if condition we require to implement the locks in Python. Let us start with multithreading and its implementation...

5 minutes read.

Django vs NodeJS

Django and NodeJS are open-source frameworks used to develop web applications. Both Django and NodeJS are cross-platform and robust technology used for developing versatile web applications and mobile applications. Django Django is...

2 minutes read.

Sentiment Analysis using NLTK

Introduction Data is being produced at an astounding rate and volume in the field of the internet and other digital services nowadays. Researchers, engineers, and data analysts often work with tabular...

7 minutes read.

Python Debugger

In this tutorial, we will understand what is debugging in general. Then we will realize what the python debugger means and what is the method to perform it. Now, let us...

3 minutes read.