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]))- A. 55 9
- B. 55 11
- C. 55 10
- 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
- What is printed? python class T: def init(self, n): self.n = n def enter(self): print('in', self.n, end=' ') return self def exit(self…
- What is printed? python a = [1, 2, 3] a[1:2] = a a.insert(-1, 'x') a.insert(99, 'y') print(a, a.pop(-2), a.index(3))
- What is printed? python print(True + True, sum([True, False, True]), isinstance(True, int), [10, 20, 30][True], 'ab' False == '')
- What is printed? python class Meta(type): def new(m, name, bases, d): d['tag'] = name.lower() return super().new(m, name, bases, d) class…
- What is printed? python print(type(10 / 5))
- Which of these built-in Python types is immutable?