How do you make a multiplication program in python?

In the program below, we have used the for loop to display the multiplication table of 12.

Source Code

# Multiplication table (from 1 to 10) in Python

num = 12

# To take input from the user
# num = int(input("Display multiplication table of? "))

# Iterate 10 times from i = 1 to 10
for i in range(1, 11):
   print(num, 'x', i, '=', num*i)

Output

12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120

Here, we have used the for loop along with the range() function to iterate 10 times. The arguments inside the range() function are (1, 11). Meaning, greater than or equal to 1 and less than 11.

We have displayed the multiplication table of variable num (which is 12 in our case). You can change the value of num in the above program to test for other values.

Problem Definition

Create a Python program to multiply two numbers.

Program

num_1 = 2
num_2 = 3
product = num_1 * num_2
print("Product of {} and {} is {}".format(num_1, num_2,product))

Output

Product of 2 and 3 is 6

First, the two numbers are stored in the variables num_1 and num_2, respectively. Multiplication in Python is done by ( * ) operator, Then the result is saved in the product variable and printed out using string formatting.

To learn more about string formatting in Python read - How To Use String Formatting In Python

However, the more memory-efficient way to perform a multiplication in Python is by not using any variables at all it can be done in a line, but it can make the code hard to read.

print(2*3)

Output

6

Problem Definition

Create a Python Program to multiply two numbers provided by the user in real-time.

Program

num_1 = input("Enter the first number")
num_2 = input("Enter the second number")

product = float(num_1) * float(num_2)

print("Product of {} and {} is {}".format(num_1, num_2,product))

Output

Enter the first number 2
Enter the second number 3
Product of 2 and 3 is 6.0

In this program first, we are taking user input with the built-in input() function of Python then before multiplying the numbers we are converting the inputs to float type using the float() function because the input() function returns the object as a string.

To learn more about Python data types read the following articles.

  • Data Types In Python
  • How To Convert Data Types in Python

PROGRAMS

How do you make a multiplication program in python?

Python program to multiply two numbers

Python program to multiply two numbers

In this tutorial, we will discuss Python program to multiply two numbers.

In this topic, we will learn how to multiply two integer number in the Python programming language

multiply two integer numbers

num1=int(input("Enter the first number: "))
#input value for variable num1
num2=int(input("Enter the second number: "))
#input value for variable num2
mul=num1*num2;
#perform multiplication operation
print("the product of given numbers is: ",mul)
#display the product

When the above code is compiled and executed, it produces the following results

Enter the first number: 23
Enter the second number is: 32
the product of the given numbers is 736

This is a simple Python program to find the product of two integer numbers.

In the above program, we declared two different integer values such as  12 and 32 stored in variables num1, num2, respectively.
Then, we can find the product of given numbers using the * operator in Python

finally, we could display the result on the screen using the print() function in Python language.

multiply two floating point numbers

num1=float(input("Enter first number: "))
#input value for variable num1
num2=float(input("Enter second number: "))
#input value for variable num2
mul=num1*num2;
#perform multiplication operation
print("the product of given numbers is:",mul)
#display the product

When the above code is compiled and executed, it produces the following results

Enter first number: 3.43
Enter second number:21.2
product of given numbers is: 72.716

This is a simple Python program to find the product of two floating point numbers.

In the above program, we declared two different floating point values such as  3.43 and 21.2 stored in variables num1, num2, respectively.
Then, we can find the product of given numbers using the * operator in Python

finally, we could display the result on the screen using the print() function in Python language.

Suggested for you

Operator in Python

Data types in Python

Similar post

Find product of two numbers using method in Java

Find product of two numbers using recursion in Java

Multiply two numbers in C language

Multiply two numbers in C++ language

Multiply two numbers in Python language

Is multiplication possible in Python?

Multiplication of two matrices X and Y is defined only if the number of columns in X is equal to the number of rows Y . If X is a n x m matrix and Y is a m x l matrix then, XY is defined and has the dimension n x l (but YX is not defined). Here are a couple of ways to implement matrix multiplication in Python.

How do you multiply variables in Python 3?

Usually, when we multiply two variables, we use x×y, where x and y are variables. However, in most programming languages, including Python, we use the * (asterisk) sign to multiply variables instead of ×. So, to take the product of two variables, we use x*y.