logo CodeStepByStep logo

recursion_mystery_div_mod

Language/Type: Python recursion

For each call to the following recursive function, write the value that would be returned.

def recursion_mystery_div_mod(n):
    if n < 0:
        return recursion_mystery_div_mod(-n)
    elif n < 10:
        return n
    else:
        return n % 10 + recursion_mystery_div_mod(n // 10)

(Side note: What is the function really doing?)

recursion_mystery_div_mod(8)
recursion_mystery_div_mod(74)
recursion_mystery_div_mod(-513)
recursion_mystery_div_mod(3052)
recursion_mystery_div_mod(82534)

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.