Recursion function in Python

后端 未结 10 2188
庸人自扰
庸人自扰 2020-12-15 11:52

Consider this basic recursion in Python:

def fibonacci(number):
    if number == 0: return 0
    elif number == 1:
        return 1
    else:
        return          


        
10条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 12:20

    You can use the rcviz module to visualize recursions by simply adding a decorator to your recursive function.

    Here's the visualization for your code above:

    Output of OP's function with rcviz

    The edges are numbered by the order in which they were traversed by the execution. The edges fade from black to grey to indicate order of traversal: black edges first, grey edges last.

    (I wrote the rcviz module on GitHub.)

提交回复
热议问题