ProgrammingVery hardCognizant GenC · Python · Advanced

What is printed?

What is printed?
def fib(n, memo={}):
    if n < 2:
        return n
    if n not in memo:
        memo[n] = fib(n - 1) + fib(n - 2)
    return memo[n]
print(fib(10), len(fib.__defaults__[0]))
  1. A. 55 9
  2. B. 55 11
  3. C. 55 10
  4. D. 89 9

Correct answer: A. 55 9

fib(10) = 55; the default dict, created once, ends up with memo keys 2 through 10, that is 9 entries.

More Python Programming questions

Exams that ask this topic