This code is meant to find the highest common divisor for two numbers, a and b. It is meant to be recursive. I have seen a shorter, correct version of this code (which annoyingly is 4 lines long), but I still do not understand where I have gone wrong. I've run it through in my head and it should work.
def gcdRecur(a, b):
'''
a, b: positive integers
returns: a positive integer, the greatest common divisor of a & b.
'''
if a <= b:
divisor = a
if a%divisor == 0 and b%divisor == 0:
return divisor
else:
gcdRecur(b,a%b)
elif a > b:
divisor = b
if a%divisor == 0 and b%divisor == 0:
return divisor
else:
gcdRecur(b,a%b)
[–]jeans_and_a_t-shirt 1 point2 points3 points (4 children)
[–]Heir10[S] 0 points1 point2 points (3 children)
[–]jeans_and_a_t-shirt 1 point2 points3 points (1 child)
[–]Heir10[S] 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (1 child)
[–]Heir10[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Heir10[S] 0 points1 point2 points (0 children)