ProgrammingHardProduct-company MCQ pattern
What is printed on the first line?
What is printed on the first line?
print(0.1 + 0.2 - 0.3 == 0, 0.1 + 0.2 - 0.3) print(1 - 0.9 == 0.1, 1 - 0.9)
- A. True 5.551115123125783e-17
- B. False 5.551115123125783e-17
- C. False 0.0
- D. False 0.09999999999999998
Correct answer: B. False 5.551115123125783e-17
The rounding errors of 0.1, 0.2 and 0.3 do not cancel, so the result is one unit of the last place away from zero. The printed value is the exact float difference.
More Python Programming questions
- 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…
- What is printed on the second line? python a, b = -13, 4 print(a // b, a % b, a // b b + a % b == a) print(int(a / b), int(-3.25), -3.25…