logo CodeStepByStep logo

recursion_mystery8

Language/Type: Python recursion

For each call to the following recursive function, write the output that is produced as it would appear on the console. Hint: To avoid re-tracing out long chains of calls, it may help you to look at your own notes on call results that you have already previously computed, and re-use those results as applicable.

def recursion_mystery8(n):
    if n <= 1:
        print(n, end="")
    else:
        print(n, "= (", end="")
        recursion_mystery8(n // 2 + n % 2)
        print(", ", end="")
        recursion_mystery8(n // 2)
        print(")", end="")
recursion_mystery8(3)
recursion_mystery8(4)
recursion_mystery8(6)
recursion_mystery8(7)

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.