ProgrammingHardInfosys HackWithInfy · TCS CodeVita
What is printed?
What is printed?
def depth(n):
return 0 if n == 0 else 1 + depth(n - 1)
try:
print(depth(500))
print(depth(5000))
except RecursionError:
print('deep')- A. 500 | deep
- B. 500 | 5000
- C. deep
- D. 1000 | deep
Correct answer: A. 500 | deep
CPython's default recursion limit is 1000 frames, so depth(500) succeeds and depth(5000) raises RecursionError, which the except branch catches.
More Python Programming questions
- What is printed? python from collections import defaultdict d = defaultdict(list) d['a'].append(1) print('b' in d, d['b'], len(d), 'b' in d)
- What is printed? python m = [[1, 2, 3], [4, 5, 6]] rot = [list(r) for r in zip(m[::-1])] print(rot)
- What is printed? python def hist(h): st = [] best = 0 h = h + [0] for i, x in enumerate(h): start = i while st and st[-1][1] >= x: idx…
- What is printed? python def knap(items, cap): dp = [0] (cap + 1) for w, v in items: for c in range(cap, w - 1, -1): dp[c] = max(dp[c]…
- What is printed? python from collections import deque def knight(src, dst): seen = {src: 0} q = deque([src]) moves = [(1, 2), (2, 1), (-1…
- For an array of n = 10^5 values, which approach counts the distinct values in every window of size k = n / 2 in the least total time?