ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
def f(n):
if n <= 1:
return n
return f(n - 1) + f(n - 2)
print(f(20), f.__defaults__)- A. 4181 None
- B. 6765 0
- C. 6765 None
- D. 6765 ()
Correct answer: C. 6765 None
f(20) is the 20th Fibonacci number with f(0)=0 and f(1)=1, which is 6765. The function has no default arguments, so __defaults__ is None.
More Python Programming questions
- What is printed? python s = 'abcabc' print(s.index('c'), s.rindex('a'), s.find('bca', 1), s.count('bc', 1, 4))
- What is printed? python nums = [4, 9, 16] print(list(map(pow, nums, [0.5] 3)), [n 0.5 for n in nums])
- What is printed? python def gen(n): for i in range(n): yield i i g = gen(4) print(sum(g), sum(g), list(gen(0)))
- What is printed? python words = ['apple', 'Bob', 'cat'] print(sorted(words, key=str.casefold)[0], sorted(words)[0], max(words, key=len))
- What is printed? python import heapq h = [(2, 'x'), (1, 'y'), (1, 'a')] heapq.heapify(h) heapq.heappush(h, (0, 'z'))…
- What is printed? python s = 'hello world' print(s.title(), s.swapcase()[:5], s.replace('l', '', 2))