In this post, we will learn how to multiply two numbers using Python Programming language.
This program asks the user to enter two numbers, then it calculates the product of these two numbers using arithmetic operators.
So, without further ado , let’s begin this tutorial.
Python Program to Multiply Two Numbers
# Python Program to Multiply Two Numbers x = int(input("Enter the first number: ")) y = int(input("Enter the second number: ")) # Multiplication of two integers mult = x * y # Displaying output print("The product of {0} and {1} is: {2}" .format(x, y, mult))
Output
Enter the first number: 6
Enter the second number: 8
The product of 6 and 8 is: 48
How Does This Program Work ?
x = int(input("Enter the first number: ")) y = int(input("Enter the second number: "))
The user is asked to enter the value of two integers. The value of these two integers get stored in the x and y named variable.
# Multiplication of two integers mult = x * y
We compute the product of two numbers using (*) arithmetic operator.
# Displaying output print("The product of {0} and {1} is: {2}" .format(x, y, mult))
Finally, the product of these two numbers is displayed on the screen using print() function.
Python Program to Multiply Two Floating Point Numbers
# Python Program to Multiply Two Floating Point Numbers a = float(input("Enter first floating point number: ")) b = float(input("Enter second floating point number: ")) # Product of two float numbers product = a * b # Displaying output print("The product of {0} and {1} is: {2}" .format(a, b, product))
Output
Enter first floating point number: 5.2
Enter second floating point number: 7.1
The product of 5.2 and 7.1 is: 36.92
Python Program to Multiply Two Numbers Using Functions
# Python Program to Multiply Two Numbers Using Functions def Multiply(x, y): return x *y a = int(input("Enter the first number: ")) b = int(input("Enter the second number: ")) # Calling out function product = Multiply(a, b) # Displaying output print("The product of {0} and {1} is: {2}" .format(a, b, product))
Output
Enter the first number: 12
Enter the second number: 15
The product of 12 and 15 is: 180
Conclusion
I hope after going through this post, you understand how to multiply two numbers using Python Programming language.
If you have any doubts regarding the program, feel free to contact us in the comment section. We will be delighted to assist you.
Also Read: