Python Program to Find Product of Three Numbers

As a part of my project, I was working with a dataset where I needed to multiply three different values together. At first glance, it looked like a simple task, but I realized many beginners often struggle with writing clean and reusable code for such cases.

In this tutorial, I will show you how to create a Python program to find product of three numbers. I will also cover multiple methods so you can pick the one that fits your needs.

I always try to simplify concepts so they are easy to understand. Multiplication in Python is easy, but learning different approaches will make you more confident as a programmer.

Method to Find Product of Three Numbers

The product of three numbers simply means multiplying them together. For example:

  • If the numbers are 2, 3, and 4, the product is 2 × 3 × 4 = 24.
  • If the numbers are 5, 10, and 2, the product is 5 × 10 × 2 = 100.

This operation is very common in real-world scenarios. For instance, imagine you are calculating the total cost of a product in the USA:

  • Quantity purchased
  • Price per unit
  • Sales tax multiplier

Multiplying these three values will give you the final cost.

1 – Use Python’s Multiplication Operator

The simplest way to calculate the product of three numbers in Python is by using the * operator.

Here’s the step-by-step code:

# Python program to find the product of three numbers

# Input three numbers
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))

# Calculate product
product = num1 * num2 * num3

# Display result
print("The product of the three numbers is:", product)

I executed the above example code and added the screenshot below.

product of three numbers
  1. I take three inputs from the user.
  2. I multiply them directly using the * operator.
  3. I print the result.

This method is the most direct and works well for small programs.

2 – Use a Function in Python

In real-world projects, I prefer writing reusable functions in Python. This makes the code easier to maintain and test.

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

def product_of_three(a, b, c):
    return a * b * c

# Example usage
result = product_of_three(7, 5, 3)
print("The product of the three numbers is:", result)

I executed the above example code and added the screenshot below.

python math prod
  • Functions allow you to reuse the same logic multiple times.
  • They make the code cleaner and more organized.
  • You can easily test them with different inputs.

For example, if you are building a shopping cart system, you can call this function every time you need to calculate the total price of an item.

3 – Use Python’s math.prod() Function

Python’s math module introduced the prod() function in version 3.8. This is a very efficient way to calculate the product of numbers in an iterable.

import math

# Python program to find the product of three numbers using math.prod()

numbers = [4, 6, 2]
product = math.prod(numbers)

print("The product of the three numbers is:", product)

I executed the above example code and added the screenshot below.

how to find the product of 3 numbers
  • It’s built-in and optimized for performance.
  • It works with lists, tuples, and other iterables.
  • It’s useful when you need to multiply more than three numbers.

For example, if you are running a financial model where you need to multiply several factors like interest rates, inflation rates, and adjustments, math.prod() is the cleanest solution.

4 – Use a Loop in Python

Sometimes, you may want to use loops instead of built-in functions in Python. This is especially useful if you are just starting with Python and want to understand how multiplication works internally.

# Python program to find the product of three numbers using a loop

numbers = [3, 8, 5]
product = 1

for num in numbers:
    product *= num

print("The product of the three numbers is:", product)
  • It helps beginners understand how multiplication is applied step by step.
  • It can be extended to any number of inputs.
  • It gives you the flexibility to add conditions while multiplying.

Handle Edge Cases

When writing real-world programs, I always think about edge cases. Here are some things you should consider:

  1. Zero as an input
  • If any of the numbers is 0, the product will always be 0.
  • Example: 5 × 0 × 10 = 0.
  1. Negative numbers
  • Multiplying negative numbers follows math rules.
  • Example: -2 × 3 × 4 = -24.
  1. Floating-point numbers
  • Python handles decimals as well.
  • Example: 2.5 × 3 × 1.2 = 9.0.
  1. Large numbers
  • Python can handle very large integers without overflow.
  • Example: 100000 × 200000 × 300000 will still work.

Real-world Example

Let’s take a practical scenario. Suppose you are calculating the total cost of buying laptops in the USA.

  • Number of laptops purchased = 3
  • Price per laptop = 1200 USD
  • Sales tax multiplier = 1.07 (7% tax)
# Real-life example: Calculate total cost of laptops with tax

def total_cost(quantity, price, tax_multiplier):
    return quantity * price * tax_multiplier

cost = total_cost(3, 1200, 1.07)
print("The total cost of laptops is: $", cost)

Output:

The total cost of laptops is: $ 3852.0

This is exactly how the multiplication of three numbers becomes useful in real-world applications.

Which Method Should You Use?

  • If you just want a quick calculation → use the * operator.
  • If you are writing reusable code → use a function.
  • If you are working with lists or many numbers → use math.prod().
  • If you are practicing logic building → try the loop method.

When I look back at my early coding days, I remember struggling with simple tasks like multiplication. Over time, I realized that understanding multiple approaches makes you a better problem solver.

Now you know four different ways to find the product of three numbers in Python. Whether you are working on a school project, a financial model, or a shopping cart system, these methods will come in handy.

You may like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.