I am trying to calculate a GCD of 2 numbers, the following code block works fine, I am using recursion, but when I am trying to return a value I am not able to do so, return a results in None
def gcd(a,b):
if b == 0:
print a
return a # This is not working
else:
gcd(b,a%b)
XX = gcd(3, 5)
print (XX)
Output:
1
None
Noneis no explicitreturnstatement is executed.gcdneeds to be returned, Likereturn gcd(b,a%b)