ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
import math print(math.floor(-2.5), math.ceil(-2.5), math.trunc(-2.5), int(-2.5), round(-2.5), -2.5 // 1)
- A. -3 -2 -2 -2 -2 -3.0
- B. -3 -2 -2 -3 -3 -3.0
- C. -2 -3 -2 -2 -2 -2.0
- D. -3 -2 -3 -2 -3 -3.0
Correct answer: A. -3 -2 -2 -2 -2 -3.0
floor goes down (-3), ceil up (-2), trunc and int() go toward zero (-2), round uses banker's rounding (-2.5 -> -2, the even neighbour), and // 1 floors but keeps the float type (-3.0).
More Python Programming questions
- What is printed? python print(3 "ab" == "ab" 3, [1] 3 is [1] 3, "%" in "100%", "100%%" % (), f"{{x}}")
- What is printed? python x = 10 s = f"{x=}, {x2=}, {x:04}, {'a' if x > 5 else 'b'}" print(s)
- What is printed? python def f(): yield 1 g = f() print(type(f).name, type(g).name, hasattr(g, "next"), iter(g) is g, callable(g))
- What is printed? python class Matrix: def init(self, r): self.r = r def getitem(self, idx): i, j = idx return self.r[i][j] def…
- What is printed? python a = [1, 2, 3] b = a[:] print(a == b, a is b, a[:] is a[:], id(a) == id(b), a.copy() == list(a))
- A service catches errors with except Exception: around its main loop. Which of the following will NOT be caught by that handler?