Skip to content
Code ReadingCalling Itself
Predict the Output

Calling Itself

f(0) and f(1) return 1; everything else adds two smaller calls. What is printed?
1def f(n):
2 if n <= 1:
3 return 1
4 return f(n - 1) + f(n - 2)
5
6print(f(6))