0
def divide(x,y):
    if x <0 or y <= 0:
        return 0,0 
    quotient = 0
    while x >= y:
        x -= y
        quotient += 1
    return quotient,x #remainder is in x

def main():
    x,y = input("Enter digits separated by comma: ").split(",")
    x,y = int(x),int(y)
    divide(x,y)
    
main()

Division of 2 numbers x by y repeatedly, subtracting y from x until y is less than x. For example, x = 11 and y = 4. The quotient is 2 (subtract twice) and remainder is 3 (11-4-4=3).

I am expecting to return tupple of (2,3) but it has been returning me none. I would like to know where I have made the mistake and how I could improve. Thank you in advance!!

2 Answers2

0

Your function is returning a tuple. You are not using it.

Change

divide(x, y)

to

res = divide(x, y)
print(res)

If you want to use the result outside main you can return it, which will look like this,

def divide(x,y):
    if x <0 or y <= 0:
        return 0,0
    quotient = 0
    while x >= y:
        x -= y
        quotient += 1
    return quotient,x #remainder is in x

def main():
    x,y = input("Enter digits separated by comma: ").split(",")
    x,y = int(x),int(y)
    return divide(x,y)

res = main() # catch the value returned
print(res) # use the returned value
Sreeram TP
  • 11,346
  • 7
  • 54
  • 108
0

Your main method does not return anything.

Other than that, your application does exatly what you want:

def divide(x,y):
    if x <0 or y <= 0:
        return 0,0
    quotient = 0
    while x >= y:
        x -= y
        quotient += 1
    return quotient,x #remainder is in x

def main():
    x,y = input("Enter digits separated by comma: ").split(",")
    x,y = int(x),int(y)
    return divide(x,y) # return the result of ``divide``.

print(main()) # do something with the result of ``main``, e.g. print it

Output:

 (2, 3)

Side node: every method in Python does return something. If you're not explicetly setting it, the result will be implicetly set to None.

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50