LearnPy Hub
← Decorators problems
Medium

Trace a Recursive Function

Write a decorator trace that prints fact(n) indented by two spaces per level of recursion depth before each call, and -> result at the same indent after it. Decorate a recursive fact(n) (fact(0) = 1) and call it with the input n.

Input

One integer 0–6.

Output

Lines.

Sample 1

Input
3
Output
fact(3)
  fact(2)
    fact(1)
      fact(0)
      -> 1
    -> 1
  -> 2
-> 6

Sample 2

Input
0
Output
fact(0)
-> 1
solution.py
Output appears here
Trace a Recursive Function · Python practice problem · LearnPy Hub