CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List
Python Code Walkthrough #48

How Many Times Fib Is Called

hardRecursion

📄 Code

Read carefully — what does this print?
1counter: dict[str, int] = {"calls": 0}
2 
3def fib(n: int) -> int:
4 counter["calls"] = counter["calls"] + 1
5 if n < 2:
6 return n
7 return fib(n - 1) + fib(n - 2)
8 
9print(fib(5))
10print(counter["calls"])

🎯 Your Answer