0
n, m = map(int, input().split())
if n < m:
    n, m = m, n

def mod(x,y):
    if x % y:
        mod(y, x % y)
    else:
        return y
        #or return(y) or return (y)

print(mod(n, m))

I'm try to make recursive function to get greatest common divisor and least common multiple, but the function does not return the variable.

I checked a variable is fine (it's exist well right before return function) and if statement is also fine but the return() function does nothing but return None.

I tried return string (return "what") but it still returns None.

Where is my mistake? And how to make return function returns variable normally?

2 Answers2

1
def mod(x,y):
    if x % y:
        return mod(y, x % y)
    else:
        return y
Ming
  • 479
  • 2
  • 11
0

You are returing "y" which is a string instead you should

 return y

which is a variable

Satyam Shankar
  • 250
  • 2
  • 12