Example: two recursive-call function
def chop(word):
if len(word) > 0:
print(word)
chop(w[1:]) # 1st recursive call
print('---')
chop(w[1:] ) # 2nd recursive call
print('*')
Solution
Notes:
- the brown circled letters indicate which print statements produce which printed lines
- the numbers above each function call frame indicate the order in which they are opened (1-15)
- the function call frames 4, 5, 7, 8, 11, 12, 14 and 15 are invoked with an empty string
('')
. This makeslen(word) > 0
False, which means nothing is printed.
Table of Contents
- Extra Recursion Practice home
- Fruitful recursion w/ Turtle graphics (from lab11)
- Predicting outcome of recursive functions (non-fruitful)
- More practice problems: Recursive Graphics
- More practice problems: More fruitful Turtle Recursion