Python program for finding greatest of 3 numbers

In this Python tutorial, we will discuss how to find the greatest of 3 numbers in Python. The purpose is to identify the largest of the three integers given as inputs and find the largest number. And also we are going to cover the following given topics.

  • Python program for finding the greatest of 3 numbers
  • Python program to find the max of 3 numbers
  • Python program to find the greatest among three numbers using the function
  • Python program to find the biggest of three numbers using nested if else-if
  • Python program to find the biggest and smallest of three numbers
  • Write a Python code to find the greatest of three numbers inputted by the users
  • Python function to find the max of three numbers
  • Python program to find the largest of three numbers using nested if
  • Python program for product of three numbers

Python program for finding the greatest of 3 numbers

  • In this section, we will discuss how to find the greatest of 3 numbers in Python.
  • The purpose is to identify the largest of the three integers given as inputs. To execute this, we check and compare the three integer inputs against one another, then publish the highest number.
  • To obtain the largest of the three numbers in this example, we will utilize a Python If statement.
  • To determine the greatest number of three, we will proceed as follows. Suppose we have three variables a,b, and c.
  • A is the largest of the three numbers if an is bigger than b and c together. When both b and c are larger than a, b is the largest of the three values. If both c and b are larger than a and b, then c is the largest of the three numbers.

Example:

Let’s take an example and check how to find the maximum number from given input of 3 numbers in Python.

Source Code:

first_val = int(input('Enter the first value:'))
second_val = int(input('Enter the second value:'))
third_val = int(input('Enter the third value:'))

greatest_val = 0

if first_val > second_val and first_val > third_val:
    greatest_val = first_val
if second_val > first_val and second_val > third_val:
    greatest_val = second_val
if third_val > first_val and third_val > second_val:
    greatest_val = third_val

print(greatest_val, "is the largest of three values.")

Here is the Screenshot of the following given code

Python program for finding the greatest of 3 numbers
Python program for finding the greatest of 3 numbers

This is an example of a python program for finding greatest of 3 numbers.

Read How to create a dictionary from two lists in python

Python program to find the max of 3 numbers

  • Here we will discuss how to find the max of 3 numbers in Python.
  • By using the max() function and the maximum value from the iterable or number of arguments supplied is returned by the max() method.
  • The largest or maximum element is returned by the max() method in Python. Either an iterable or a straight set of elements can be supplied as the parameter. Python’s max function returns TypeError when it receives values of various data types.
  • Alternatively, the max() function in Python throws ValueError if the default value is not given in the parameter and the iterable is empty.

Syntax:

Here is the Syntax of the max() function in Python

max(iterable, *iterables, key, default)
  • It consists of a few parameters
    • iterable: This parameter defines the iterable object that stores one or more iterable items like a list, tuple, etc.
    • Key: If multiple iterables are supplied, this is also an optional parameter. Based on the result of these key functions, comparisons between the iterables are done.

Example:

value_1 = int(input('Enter the first value: '))
value_2 = int(input('Enter the second value: '))
value_3 = int(input('Enter the third value: '))

#Display the value 
print('The maximum number = ', max(value_1, value_2, value_3))

In the following given code first, we have created three variables and used the input function to take input from the user. Now we have to find the maximum value from the input values for this we have used the max() function.

Here is the execution of the following given code

Python program to find the max of 3 numbers
Python program to find the max of 3 numbers

This is how to find the max of 3 numbers in Python.

Read Python dictionary pop

Python program to find greatest among three numbers using the function

  • In this section, we will discuss how to find the greatest among three numbers by using a function in Python.
  • To perform this particular task we are going to use the Ternary Operator Ternary operators, also referred to as conditional expressions, are types of operators that evaluate a value dependent on whether a certain condition is true or false.

Example:

Let’s take an example and check how to find the greatest among three numbers by using a function.

Source Code:

first_val, second_val, third_val = 56 , 28 , 38
result = first_val if first_val>second_val else second_val
result = third_val if third_val>result else result
print(result)

In the following given code first, we declared three variables and assign them to an integer value. Next, we used the condition if first value is greater than the second value else same in the second_ val is greater

You can refer to the below Screenshot

Python program to find the greatest among three numbers using function
Python program to find the greatest among three numbers using the function

This is how to find the greatest among three numbers using a function in Python.

Read Python loop through a list

Python program to find biggest of three numbers using nested if else-if

  • In this example, we will discuss how to find the biggest of three numbers using nested if else-if condition in Python.
  • You can build an if chain using the if/else if statement. The if statements are evaluated one at a time until one of them if expressions evaluate to be true or the end of the if/else chain is reached. There is no execution of any code blocks if the if/else chain comes to a conclusion without a true expression.
  • In this example, we will use the input function to take the input from the user and set the condition if a>b>c then if it is greater than other numbers it will store in the result.

Example:

USA_no = int(input('Enter first value : '))
Second_val = int(input('Enter second value : '))
third_val = int(input('Enter third value  : '))

result = 0

if USA_no > Second_val and USA_no > third_val :
    result = USA_no
elif Second_val > third_val :
    result = Second_val
else :
    result = third_val

print(result, "is the greatest of three numbers.")

Here is the implementation of the following given code

Python program to find the biggest of three numbers using nested if else if
Python program to find the biggest of three numbers using nested if else if

This is an example of Python program to find biggest of three numbers using nested if else-if.

Read Python dictionary comprehension

Python program to find biggest and smallest of three numbers

  • In this example, we will find the maximum and minimum number among the given three numbers in Python.
  • To perform this task we are going to use the max() function and min() function and the largest or maximum element is returned by the max() method in Python. Either an iterable or a straight set of elements can be supplied as the parameter. Python’s max function returns TypeError when it receives values of various data types.
  • The built-in functions min() and max() each have a distinct signature that allows you to call them with either an iterable or two or more normal arguments as their initial parameter.

Example:

value_1 = int(input('Enter the first value: '))
value_2 = int(input('Enter the second value: '))
value_3 = int(input('Enter the third value: '))

#Display the value 
print('The maximum number = ', max(value_1, value_2, value_3))
print('The minimum number = ', min(value_1, value_2, value_3))

Here is the execution of the following given code

Python program to find the biggest and smallest of three numbers
Python program to find the biggest and smallest of three numbers

This is an example of finding the biggest and smallest of three numbers in Python.

Read: How to Check if a String contains a Substring in Python

Write a Python code to find the greatest of three numbers inputted by the users

  • The purpose is to identify the largest of the three integers given as inputs. To execute this, we check and compare the three integer inputs against one another, then publish the highest number.
  • To obtain the largest of the three numbers in this example, we will utilize a Python If statement.
  • In this example, we will use the input function to take the input from the user and set the condition which number is greater than other numbers.

Example:

first_val = int(input('Enter the first value:'))
second_val = int(input('Enter the second value:'))
third_val = int(input('Enter the third value:'))

greatest_val = 0

if first_val > second_val and first_val > third_val:
    greatest_val = first_val
if second_val > first_val and second_val > third_val:
    greatest_val = second_val
if third_val > first_val and third_val > second_val:
    greatest_val = third_val

print(greatest_val, "is the largest of three values.")

Here is the Output of the following given code

Write a Python code to find the greatest of three numbers inputted by the users
Write a Python code to find the greatest of three numbers inputted by the users

This is an example of Python find the greatest of three numbers inputted by the users.

Read For loop vs while loop in Python

Python function to find the max of three numbers

  • Using the max() function, we were able to determine the largest of the three values in this case. To locate the greatest number in an iterable, we can use the built-in Python method max().
  • By using the max() function and the maximum value from the iterable or number of arguments supplied is returned by the max() method.
  • The largest or maximum element is returned by the max() method in Python. Either an iterable or a straight set of elements can be supplied as the parameter. Python’s max function returns TypeError when it receives values of various data types.

Example:

value_1 = int(input("Enter the first value: "))
value_2 = int(input("Enter the second value: "))
value_3 = int(input("Enter the third value: "))

result=max(value_1, value_2,value_3)
print(result)

You can refer to the below Screenshot

Python function to find the max of three numbers
Python function to find the max of three numbers

This is how we can find the maximum value from the given three numbers in Python by using the max() function.

Read Python dictionary find a key by value

Python program to find the largest of three numbers using nested if

  • In this section, we will discuss how to find the largest of three numbers by using the nested if method.
  • To perform this particular task we are going to use only if statement and within this we are going to applied the and operation as well as set the condition if statement’s two conditions, that verifies programme flow only occurs inside the if statement’s body if both conditions are evaluated as True.

Example:

number_1 = int(input("Enter the first value: "))
number_2 = int(input("Enter the second value: "))
number_3 = int(input("Enter the third value: "))

if number_1>number_2 and number_1>number_3 :
    print("\nLargest number:", number_1)
if number_2>number_1 and number_2>number_3 :
    print("\nLargest number:", number_2)
if number_3 >number_1 and number_3 >number_2:
    print("\nLargest number:", number_3 ) 

In the following given code first we will take the input from the user by using the input() function and then set the condition if number_1 is greater than number_2 and number_3 then it will display the largest number. Similarly in the case of second if condition number 2 is greater of number_1 and number_3.

You can refer to the below Screenshot

Python program to find the largest of three numbers using nested if
Python program to find the largest of three numbers using nested if

This is how to find the largest of three numbers using nested if in Python.

Read: Python program for bubble sort

Python program for product of three numbers

  • In this section, we will discuss how to get the product of three numbers in Python.
  • The result of multiplying all the values is a simple task. For instance, the result will be 90 for the list [2, 5, 9]. We will go over the various methods for calculating the sum of all the numbers in a list.
  • To perform this task first we will use the * operator and it is the simplest and fastest approach to multiply three numbers in Python . While declaring the variables, we will take three numbers and compute the product of these numbers. In the end, the multiplication value will be shown on the screen after being placed in the product variable.

Example:

Let’s take an example and check how to get the product of three numbers in Python.

Source Code:

num_1 = 15
num_2 = 65
num_3 = 34

# calculate product
result = num_1 * num_2 * num_3

# Display multiplication value
print("Multiplication of Number:", result)

In the above code first we will declare three variables and assign integer values. Next we used the * operator for multiplication of given three numbers. After executing this code it will display the product of three numbers.

Here is the execution of the following given code

Python program for product of three numbers
Python program for product of three numbers

In this Python tutorial, we will discuss how to find the greatest of 3 numbers in Python. The purpose is to identify the largest of the three integers given as inputs and find the largest number. And also we are going to cover the following given topics.

  • Python program for finding the greatest of 3 numbers
  • Python program to find the max of 3 numbers
  • Python program to find the greatest among three numbers using the function
  • Python program to find the biggest of three numbers using nested if else-if
  • Python program to find the biggest and smallest of three numbers
  • Write a Python code to find the greatest of three numbers inputted by the users

You may like the following Python tutorials: