ProgrammingVery hardProduct Company SDE · Python internals

What does the following Python 3 code print? def fib(n, memo={}): if n in memo: return memo[n] if n <= 1: return n memo[n] = fib(n - 1, memo) + fib(n - 2, memo) return memo[n] print(fib(10))

  1. A. 55
  2. B. 89
  3. C. 144
  4. D. 34

Correct answer: A. 55

Memoized Fibonacci: fib(10) follows the standard sequence 0,1,1,2,3,5,8,13,21,34,55, so fib(10)=55.

More Python Programming questions

Exams that ask this topic