ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
x = 10**20 + 1 y = float(x) print(int(y) == x, int(y) - x, y == 10**20, float(x) == y)
- A. True -1 True True
- B. False 2 True True
- C. False -1 False True
- D. False -1 True True
Correct answer: D. False -1 True True
Converting to float rounds 10**20 + 1 back to 10**20, so int(y) differs from x by -1. The round trip is lossy, but both float conversions produce the same double.
More Python Programming questions
- What is printed? python import math print(math.floor(1e300) == 10300, math.floor(1e300) == int(1e300), round(1e300) == 10300)
- What is printed? python print(0.1 + 0.2 != 0.3, (0.1 + 0.2) - 0.3 < 1e-16, abs((0.1 + 0.2) - 0.3) <= 5e-17)
- What is printed? python print(max('zebra', 'Zebra'), min('a', 'B'), sorted('bA', key=ord)[0], 'bA' > 'Ab')
- What is printed? python print([1, 2] < [1, 2, 0], [1, 2] < [1, 3, 0], (1, 2) < (1, 2, 0), 'ab' < 'abc')
- What is printed? python print(hex(255), hex(-255), oct(-8), bin(0), int('-ff', 16), int('0xFF', 0))
- What is printed? python print(int('8' 3) % 7, int('8' 3, 16) % 7, pow(10, 3, 7), 888 % 7)