ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
def f(x):
if x > 0:
return x
print(f(1), f(-1), f(0) or "zero", f(2) and f(-2))- A. 1 None None None
- B. 1 -1 zero -2
- C. 1 None zero 2
- D. 1 None zero None
Correct answer: D. 1 None zero None
A function that ends without return gives None. `None or 'zero'` returns 'zero'; `2 and None` returns its second operand None, since 2 is truthy.
More Python Programming questions
- What is printed? python print(repr([] or {} or 0 or ""), "a" and "b" or "c", "" and 1 or 0, not "0")
- What is printed? python def f(a, b): return a // b if b else None vals = [(7, 2), (-7, 2), (7, 0), (7.0, -2)] print([f(p) for p in vals]…
- What is printed? python print(int("12", 8), oct(64), hex(-255), int("z", 36), format(10, "b").zfill(6))
- What is printed? python x = 2 63 print(x.bitlength(), (x - 1).bitlength(), x >> 62, (-1) >> 100, 1 << 0, (5).tobytes(2, "big"))
- What is printed? python import math print(math.floor(-2.5), math.ceil(-2.5), math.trunc(-2.5), int(-2.5), round(-2.5), -2.5 // 1)
- What is printed? python print(3 "ab" == "ab" 3, [1] 3 is [1] 3, "%" in "100%", "100%%" % (), f"{{x}}")