ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
def f(x):
try:
r = 10 // x
except ZeroDivisionError:
return "Z"
else:
return r
finally:
print("F", end=" ")
print(f(0), f(3))- A. Z F 3 F
- B. F Z F 3
- C. F F Z 3
- D. Z 3 F F
Correct answer: C. F F Z 3
Both arguments of the outer print are evaluated first. Each call runs its finally block, which prints "F " before the function actually returns. f(0) returns "Z" and f(3) returns 10 // 3 = 3 (from the else block). Only then does print write "Z 3".
More Python Programming questions
- What is printed? python class P: def repr(self): return "R" def str(self): return "S" print(P(), [P()], f"{P()!r}")
- What is printed? python class K: def eq(self, other): return True try: print({K(): 1}) except TypeError: print("TypeError")
- What is printed? python it = iter([1, 2, 3, 4, 5]) print(list(zip(it, it)))
- What is printed? python x = 1 x, y = x + 1, x 10 print(x, y)
- What is printed? python print(any([]), all([]), all([[]]))
- What is printed? python class C: n = 0 def init(self): C.n += 1 @classmethod def total(cls): return cls.n class D(C): pass D(); C(); D()…