ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
def outer():
results = []
def rec(n):
if n == 0:
results.append("x")
return
for _ in range(n):
rec(n - 1)
rec(3)
return len(results)
print(outer())- A. 6
- B. 3
- C. 9
- D. 27
Correct answer: A. 6
rec(n) makes n calls to rec(n-1), so the number of leaves is n! = 3 * 2 * 1 = 6.
More Python Programming questions
- What is printed? python a = "abc" b = "".join(["a", "b", "c"]) print(a == b, a is b or True, sorted(set(a + b)), a.find("c") ==…
- What is printed? python temps = {"mon": 30, "tue": 25, "wed": 35} hot = [d for d, t in temps.items() if t > 28] coolest = min(temps…
- What is printed? python s = "level" t = "".join(reversed(s)) u = s[::-1] print(s == t == u, t is s, list(reversed([1, 2])) == [2, 1]…
- What is printed? python marks = [72, 85, 64, 85, 90] print(marks.index(85), marks.count(85), sorted(marks)[len(marks) // 2]…
- What is printed? python inventory = {"pen": 3, "ink": 0} inventory["pad"] = inventory.get("pad", 0) + 5 inventory.update(ink=2)…
- What is printed? python def area(w, h=None): if h is None: h = w return w h print(area(3), area(3, 4), area(h=2, w=5), area([2, 6]))