Python program to multiply two numbers without using arithmetic operator
- Home
- Calculations
- Python program to multiply two numbers without using arithmetic operator
- On
- By
- 0 Comment
- Categories: Calculations, multiply
Python program to multiply two numbers without using arithmetic operator
Python program to multiply two numbers without using arithmetic operator
problem – Python program to multiply two numbers without using arithmetic operator
In this tutorial, we will discuss the concept of multiplying two numbers without using arithmetic operator in Python language.
In this post, we will learn how to get the product of two number without arithmetic operator in Python programming language
Python program to find product of two numbers
Using for loop – Program 1
This program is used to find the multiplication of two numbers entered by the user – using for loop without arithmetic operator
#How to print product of two numbers without using "*" operator in Python num1=int(input("Enter a number for num1: "))#get input from user for num1 num2=int(input("Enter a number for num2: "))#get input from user for num2 product=0 for i in range (1,num2+1): #Python for loop product=product+num1 #product+=num1 print("Multiplication of numbers: ",product) #Display multiplication of numbers
When the above code is executed, it produces the following result
Enter a number for num1: 25 Enter a number for num2: 50 Multiplication of numbers: 1250
Using function – Program 2
This program is used to find the multiplication of two numbers entered by the user – using if elif statements without arithmetic operator
x=int(input("Enter a number for x: "))#get input from user for x y=int(input("Enter a number for y: "))#get input from user for y def findProduct(x,y): #Python function if y<0: return -findProduct(x,-y) elif y == 0: return 0 elif y == 1: return x else: return x+ findProduct(x,y-1) print("product of two numbers: ",findProduct(x,y)) #Display result on the screen
When the above code is executed, it produces the following result
Enter a number for x: 30 Enter a number for y: 12 product of two numbers: 360
Similar post
C program to multiply two numbers without using arithmetic operator
C++ program to multiply two numbers without using arithmetic operator
Java program to multiply two numbers without using arithmetic operator
Multiply two numbers in Python
Suggested for you
If elif statements in Python