ProgrammingModerateTCS NQT · Infosys
What is printed on the second line?
What is printed on the second line?
import math print(math.isclose(1e9, 1e9 + 1e-3), math.isclose(1e9, 1e9 + 1, rel_tol=1e-9)) print(round(1e9 + 0.5) - 1e9, 1e9 + 0.5 == 1000000000.5)
- A. 0.0 True
- B. 0.0 False
- C. 1.0 True
- D. 0.5 True
Correct answer: A. 0.0 True
round uses half-to-even, so 1000000000.5 rounds to the even 1000000000. The literal 1e9 + 0.5 is exact at this magnitude, so the equality holds.
More Python Programming questions
- What is printed on the first line? python print(0.1 + 0.2 - 0.3 == 0, 0.1 + 0.2 - 0.3) print(1 - 0.9 == 0.1, 1 - 0.9)
- What is printed? python import sys print(sys.floatinfo.epsilon, 1.0 + sys.floatinfo.epsilon > 1.0, 1.0 + sys.floatinfo.epsilon / 2 > 1.0)
- What is printed on the first line? python print(263 2-63 == 1.0, 264 + 1.0 - 264, (264 + 1) - 264) print(float(264 + 1) - float(264))
- What is printed on the first line? python print(7 % -3, -7 % 3, 7 % 3, -7 % -3) print(-7 // -3, 7 // -3, -7 // 3)
- What is printed on the second line? python def mod(a, m): r = a % m return r + m if r < 0 else r print(mod(-1, 5), mod(-5, 5), mod(-6, 5))…
- What is printed on the first line? python M = 109 + 7 print((-1) % M, (262) % M, pow(3, M - 2, M) 3 % M) print(((-5) % 3) ((-5) % 3), (-5…