Python Program to Find Product of Three Numbers [3 Methods]

In this Python tutorial, I will explain how to write different Python program to find product of three numbers.

Here, I will show different methods to find the product of three numbers in Python, such as using the multiplication operator(*), the custom function, and the prod() function from the math module.

Python program to find product of three numbers using the multiplication operator(*)

The * operator in Python finds the product of 2 values. So, we will use the * operator twice to get the product of three numbers.

To find the product of three numbers in Python using the * operator, I will take three numbers, suppose 4, 7, and 9.

In this Python program, we will ask user to enter three value, so that the user will enter the three value as per the need.

This is the complete Python program to find the product of three numbers, as shown below.

first_number = float(input('Enter first number: '))
second_number = float(input('Enter second number: '))
third_number = float(input('Enter third number: '))

product_of_three_numbers = first_number * second_number * third_number
print("The product of number: %0.1f" %product_of_three_numbers)

Note: I have used %0.1f in this Python program to store the one decimal point and the value.

Now, ask the user to enter the three numbers by using the code presented below:

first_number = float(input('Enter first number: '))
second_number = float(input('Enter second number: '))
third_number = float(input('Enter third number: '))

You can see the screenshot below after the code gets executed and gives the result.

Python Program to Find Product of Three Numbers

Python program to find the product of three numbers using a custom function

This is the method where we have created a custom function per the requirement to find the product of three numbers in Python.

When a user enters the 3 numbers, it will give the product it. In this Python code, I have used %0.2f so that it can store float values up to two decimal points.

def product_of_3_numbers(first_num, second_num, third_num):
    product = (first_num*second_num*third_num)
    return product
first_num = float(input('Enter first number: '))
second_num = float(input('Enter second number: '))
third_num = float(input('Enter third number: '))

product = product_of_3_numbers(first_num, second_num, third_num)
print("The product of 3 number: %0.2f" %product)

Output: Refers to the screenshot below showing the output after the Python program gets executed.

How to find the product of three numbers in Python using custom function

How to find the product of three numbers in Python using a math module

Python provides a built-in math module that you can use for mathematical tasks. In this case, I will import the math module that provides the set of methods and constants.

Here is the complete code of Python to find the product of three numbers using a math module.

import math

def product_of_3_numbers(list_of_3num):
     return math.prod(list_of_3num)
    
input_numbers = [4,7,13]
print("The product 3 numbers: ") 
print(product_of_3_numbers(input_numbers))

Here, I have used math.prod() function will provide the product of all elements in an iterable. It takes only one positional argument.

return math.prod(list_of_3num)

Output: You can see the below image, after it executed the Python program it gives the output.

Program to find the product of three elements in Python

Conclusion

In this post, I have demonstrated the steps to find the products of the three numbers in Python. Additionally, I have explained three methods to write a Python program to find the product of three numbers, such as using the multiplication operator (*), a custom function, and a math module.

The choice of the method depends upon your code requirement.

You may also like to read: