ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
print(f'{0.1 + 0.2:.17g}', f'{1/7:.10f}', f'{100/3:.0f}', f'{2.345:.2f}')- A. 0.3 0.1428571429 33 2.35
- B. 0.30000000000000004 0.1428571429 33 2.35
- C. 0.30000000000000004 0.142857 33 2.35
- D. 0.30000000000000004 0.1428571429 33 2.34
Correct answer: B. 0.30000000000000004 0.1428571429 33 2.35
Seventeen significant digits reveal the binary error in 0.1 + 0.2. 2.345 is stored slightly above the midpoint, so it rounds up to 2.35 at two places.
More Python Programming questions
- What is printed? python a = [3, 1, 2] b = sorted(a, key=lambda x: -x) a.sort(reverse=True) print(a == b, a, b)
- What is printed? python print(pow(7, 222, 10), pow(7, 222, 1000), 7222 % 1000, pow(-7, 3, -5))
- What is printed? python print(int(True) + int('0b11', 2), int(3.7 // 1), int(-0.5), round(-0.5), round(0.5))
- What is printed? python n = 0b10110000 print(n & -n, n & (n - 1), bin(n >> 4), n.bitcount())
- What is printed? python a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b, a ^ b)
- What is printed? python print(0xFF >> 4 << 4 == 0xF0, 1 << 63 > 0, (1 << 63) - 1 == 263 - 1, -(1 << 63) >> 63)