ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
def apply_twice(f):
def wrapper(x):
return f(f(x))
return wrapper
@apply_twice
def inc(x):
return x + 1
print(inc(5))- A. 6
- B. 7
- C. 12
- D. 10
Correct answer: B. 7
apply_twice makes inc call the original increment function twice: f(f(5)) = f(6) = 7.
More Python Programming questions
- What is printed? python def outerdeco(f): print("setup") def wrapper(a, kw): print("call") return f(a, kw) return wrapper @outerdeco def…
- What is printed? python def h(a, b, c): return a + b + c args = [1, 2, 3] print(h(args)) args2 = [1, 2] try: print(h(args2)) except…
- What is printed? python def k(a, , b): return a + b try: k(1, 2) except TypeError: print("TypeError") print(k(1, b=2))
- What is printed? python def n(kw): return kw print(n({"a": 1}, {"b": 2}))
- What is printed? python def p(a, b, c=3): return a, b, c d = {"a": 1, "b": 2, "c": 10} print(p(d))
- What is printed? python def r(args): return sum(args) l = [1, 2, 3] print(r(l, l))