Here is my code:
def gcd(a,b):
if a%b == 0:
return b
print b
elif b%a == 0:
return a
print a
else:
if a > b:
gcd(a%b,b)
elif b > a:
gcd(b%a,a)
else:
return a
print a
def lcm(a,b):
if a==b:
return a
else:
y = gcd(a,b)
return (a*b)/y
print (a*b)/y
What am I doing wrong? I keep getting an error because apparently y = gcd(a,b)
is a NoneType
and it must be an integer. But from what I see it is an integer.
Put
return
in front of your recursive calls togcd
. Otherwise it returnsNone
if it ends up in one of those branches.The
print
statements after yourreturn
s are never reached.