How to multiply variables in python – Python Program to Multiply Two Numbers Without Using Multiplication(*) Operator

How to multiply variables in python: In the previous article, we have discussed Python Program to Swap Two Numbers using Bitwise Operators

Given two numbers and the task is to multiply the given two numbers without using multiplication(*) Operator. Python program to multiply two numbers, python code to multiply two numbers, Multiplying Variables In Python you can find in Python List Multiplication Operator.

Examples to multiply two numbers without using multiplication operator in python:

Example1:

Input:

Given First Number = 3
Given Second Number = 6

Output:

The multiplication of given two numbers{ 3 * 6 } =  18

Example2:

Input:

Given First Number =  15
Given Second Number = 4

Output:

The multiplication of given two numbers{ 15 * 4 } =  60

Program to Multiply Two Numbers Without Using Multiplication(*) Operator in Python

Python list multiplication operator: Below are the ways given that to multiply two numbers without using * Operator in Python:

Method #1: Using For Loop (Static Input)

Approach:

  • Give the first number as static input and store it in a variable.
  • Give the second number as static input and store it in another variable.
  • Take a variable say rslt_sum and initialize its value to 0.
  • Loop from 1 to the given first number using the for loop.
  • Inside the loop, add the given second number to the above-initialized variable rslt_sum and store it in the same variable rslt_sum.
  • Print the variable rslt_sum to get the multiplication of given two numbers without using the multiplication(*) Operator.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as static input and store it in a variable.
fst_numb = 3
# Give the second number as static input and store it in another variable.
scnd_numb = 6
# Take a variable say rslt_sum and initialize its value to 0.
rslt_sum = 0
# Loop from 1 to the given first number using the for loop.
for itr in range(1, fst_numb+1):
    # Inside the loop, add the given second number to the above-initialized variable
    # rslt_sum and store it in the same variable rslt_sum.
    rslt_sum = rslt_sum+scnd_numb
# Print the variable rslt_sum to get the multiplication of given two numbers without
# using the multiplication(*) Operator.
print("The multiplication of given two numbers{",
      fst_numb, "*", scnd_numb, "} = ", rslt_sum)

Output:

The multiplication of given two numbers{ 3 * 6 } =  18

Method #2: Using For loop (User Input)

Approach:

  • Give the first number as user input using the int(input()) function and store it in a variable.
  • Give the second number as user input using the int(input()) function and store it in another variable.
  • Take a variable say rslt_sum and initialize its value to 0.
  • Loop from 1 to the given first number using the for loop.
  • Inside the loop, add the given second number to the above-initialized variable rslt_sum and store it in the same variable rslt_sum.
  • Print the variable rslt_sum to get the multiplication of given two numbers without using the multiplication(*) Operator.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as user input using the int(input()) function and
# store it in a variable.
fst_numb = int(input("Enter some random number = "))
# Give the second number as user input using the int(input()) function and
# store it in another variable.
scnd_numb = int(input("Enter some random number = "))
# Take a variable say rslt_sum and initialize its value to 0.
rslt_sum = 0
# Loop from 1 to the given first number using the for loop.
for itr in range(1, fst_numb+1):
    # Inside the loop, add the given second number to the above-initialized variable
    # rslt_sum and store it in the same variable rslt_sum.
    rslt_sum = rslt_sum+scnd_numb
# Print the variable rslt_sum to get the multiplication of given two numbers without
# using the multiplication(*) Operator.
print("The multiplication of given two numbers{",
      fst_numb, "*", scnd_numb, "} = ", rslt_sum)

Output:

Enter some random number = 15
Enter some random number = 4
The multiplication of given two numbers{ 15 * 4 } = 60

Explore more Example Python Programs with output and explanation and practice them for your interviews, assignments and stand out from the rest of the crowd.

Recommended Reading On: Python Program to Multiply Two Numbers Using Recursion

Test yourself on Multiply 2 Numbers Without Using * In Python:

  1. Python Program To Multiply Two Numbers Without Using * Operator
  2. How To Multiply Two Numbers Without Using * In Python
  3. Write A Program To Multiply Two Numbers Without Using * Operator In Python
  4. How To Multiply Variables In PythonMultiply Without Using * Python
  5. How To Multiply Numbers In Python 3
  6. How To Multiply Without Using * In Python
  7. How To Multiply Two Variables In Python
  8. How To Multiply Two Numbers Without Using *
  9. How To Multiply Numbers In Python

Related Posts On: