Skip to content
Home » Divide Two Integers Without using Division Operator in Python

Divide Two Integers Without using Division Operator in Python

Learn about Divide Two Integers Without using Division Operator in Python in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Divide Two Integers Without using Division Operator in Python

The below program divides two numbers without using any division operator.

def div_Num(x,y):
    if (y==0):
        return 0;
    elif (x-y==0):
        return 1;
    elif (x<y):
        return 0;
    else:
        return (1+div_Num(x-y,y));

# inputs
num1 = int(input('first number: '))
num2 = int(input('second number: '))

# function call
division = div_Num(num1, num2)

# print result
print("The division of {0} and {1} is {2}"
               .format(num1,num2,division))

Output:

first number: 9
second number: 3
The division of 9 and 3 is 3

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Program to Divide Two Integers in Python using Function