ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
def f(n):
try:
if n:
raise IndexError
return "body"
except IndexError:
return "except"
else:
return "else"
finally:
print("fin", end=" ")
print(f(0), f(1))- A. fin body fin except
- B. fin fin body except
- C. body fin except fin
- D. fin fin else except
Correct answer: B. fin fin body except
A return inside the try body skips the else clause. Both calls run finally (printing fin) before print receives its arguments, so both 'fin' appear before the returned values.
More Python Programming questions
- What is printed? python import math x = float("inf") print(x - x, x 0 == x 0, math.isnan(x / x), -x < 0 < x, 1e308 10 == x)
- What is printed? python print(0.1 3, round(0.1 3, 2), 1.1 + 2.2 == 3.3, round(1.1 + 2.2, 1) == 3.3)
- What is printed? python print(round(0.125, 2), round(2.675, 2), round(-1.5), round(25, -1), round(35, -1))
- What is printed? python print(int("٤٢"), "²".isdigit(), "²".isdecimal(), "½".isnumeric(), "4.2".isdigit())
- What is printed? python a = 10 16 print(float(a + 1) == float(a), int(float(2 53 + 1)) - 2 53, 2 53 + 1.0 == 2 53)
- What is printed? python print(divmod(-17, 5), divmod(17, -5), -17 % -5, pow(3, -1, 7))