Program For Division Two Numbers Operator Without Using Division() Operator

Python Program For Division Two Numbers Operator Without Using Division(/) Operator

In the previous article, we have discussed Python Program to Subtract Two Numbers Without Using Minus(-) Operator

Given two numbers and the task is to find the division of given two numbers without using Division(/)  Operator in python.

Examples:

Example1:

Input:

Given First Number = 400
Given Second Number = 200

Output:

The Division of above given two numbers{ 400 / 200 } =2

Example2:

Input:

Given First Number = 75
Given Second Number = 15

Output:

The Division of above given two numbers{ 75 / 15 } =5

Program For Division Two Numbers Operator Without Using Division(/) Operator in Python

Below are the ways to find the division of given two numbers without using the division(/) operator in python:

Method #1: Using While 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_divsn and initialize its value to 0.
  • Loop until the given first number is greater than or equal to the given second number using the while loop.
  • Inside the loop, subtract the second number from the given first number and store the result in the first number.
  • Increment the value of the above-initialized variable rslt_divsn by 1 and store it in the same variable.
  • Print rslt_divsn to get the division of given two numbers without using the division(/) 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 = 400
# Give the second number as static input and store it in another variable.
scnd_numb = 200
# Take a variable say rslt_divsn and initialize its value to 0.
rslt_divsn = 0
print("The Division of above given two numbers{",
      fst_numb, "/", scnd_numb, "} =", end="")
# Loop until the given first number is greater than or equal to the given second
# number using the while loop.
while fst_numb >= scnd_numb:
    # Inside the loop, subtract the second number from the given first number and store
    # the result in the first number.
    fst_numb = fst_numb-scnd_numb
    # Increment the value of the above-initialized variable rslt_divsn by 1 and store it in
    # the same variable.
    rslt_divsn += 1
# Print rslt_divsn to get the division of given two numbers without using the division(/)
# operator.
print(rslt_divsn)

Output:

The Division of above given two numbers{ 400 / 200 } =2

Method #2: Using While 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_divsn and initialize its value to 0.
  • Loop until the given first number is greater than or equal to the given second number using the while loop.
  • Inside the loop, subtract the second number from the given first number and store the result in the first number.
  • Increment the value of the above-initialized variable rslt_divsn by 1 and store it in the same variable.
  • Print rslt_divsn to get the division of given two numbers without using the division(/) operator.
  • The Exit of the Program.

Note: If you want to get the result in float format give float in place if int.

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_divsn and initialize its value to 0.
rslt_divsn = 0
print("The Division of above given two numbers{",
      fst_numb, "/", scnd_numb, "} =", end="")
# Loop until the given first number is greater than or equal to the given second
# number using the while loop.
while fst_numb >= scnd_numb:
    # Inside the loop, subtract the second number from the given first number and store
    # the result in the first number.
    fst_numb = fst_numb-scnd_numb
    # Increment the value of the above-initialized variable rslt_divsn by 1 and store it in
    # the same variable.
    rslt_divsn += 1
# Print rslt_divsn to get the division of given two numbers without using the division(/)
# operator.
print(rslt_divsn)

Output:

Enter some random number = 450
Enter some random number = 15
The Division of above given two numbers{ 450 / 15 } =30

If you are new to the Python Programming Language then practice using our Python Programming Examples for Beginners as our expert team has designed them from scratch.