0
def even_divide_count(num1, num2):
    y = 0
    number = num1 // num2
    if number % 2 == 1 or number == 0:
        return 0
    else:
        even_divide_count(number, num2)
        y += 1
    return y

I apologize because this is the first question I'm asking on stack overflow so apologizes for the formatting. I'm attempting to maintain the value for the variable y through recursion however the maximum value I get when y is returned is 1 as it doesn't end up adding all the y values through levels of incursion. Any help is greatly appreciated!

*updated because I forgot a line

def even_divide_count(num1, num2):
    y = 0
    number = num1 // num2
    if number % 2 == 1 or number == 0:
        return 0
    else:
        1 + even_divide_count(number, num2)
        y += 1
    return y

*found my answer, it's posted above

Miller25
  • 9
  • 2
  • Your code never modifies `y` but rather just returns the unmodified value. I don't see why you expect `y` to ever change. – John Coleman Nov 03 '21 at 17:47
  • This code should always return 0 because y is not updated at all. Do you want to count the number of division by num2? – Kota Mori Nov 03 '21 at 17:48
  • 2
    You don't need `y` at all. You return either `0` or `1 + even_divide_count(...)`. Basically, the call stack holds the return value of the recursive call for you. – chepner Nov 03 '21 at 17:48
  • It's not entirely clear what this function is *supposed* to calculate, though. I don't see why the parity of the quotient is relevant, given the name of the function. – chepner Nov 03 '21 at 17:54

0 Answers0