logo CodeStepByStep logo

recursion_mystery2_x

Language/Type: Python recursion

For each of the calls to the following recursive function below, indicate what output is produced:

def recursion_mystery2_x(n):
    print("( ", end="")
    helper(n)
    print(") ( ", end="")
    helper(n)
    print(")", end="")

def helper(n):
    if n <= 1:
        print(n, "= ", end="")
    else:
        print((n % 2), end=" ")
        helper(n // 2)
        print(n, end=" ")
        n -= 1
recursion_mystery2_x(8)
recursion_mystery2_x(25)
recursion_mystery2_x(46)

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.