ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(0.1 * 3 == 0.3, 0.1 * 3, 0.3 * 3 == 0.9)
- A. False 0.30000000000000004 False
- B. True 0.3 True
- C. False 0.3 False
- D. False 0.30000000000000004 True
Correct answer: A. False 0.30000000000000004 False
0.1 * 3 and 0.3 * 3 both carry binary rounding error, so the equality tests with the decimal literals fail even though the maths says they hold.
More Python Programming questions
- What is printed? python inf = float('inf') print(inf > 10400, inf - inf == 0, -inf < -10400, inf == inf)
- What is printed? python print(len(str(21000)), sum(int(d) for d in str(2100)))
- What is printed? python import math print(math.gcd(0, -6), math.lcm(4, 6), -7 % -3, math.lcm(0, 5))
- What is printed? python x = 6 print(x & (x - 1), x & -x, (x ^ (x >> 1)) & 1, x.bitlength(), (-x).bitlength())
- What is printed? python print(bin(10 ^ 6), 10 ^ 6 ^ 6, 3 ^ 5 ^ 3 ^ 5, ~-1, -~1)
- What is printed? python a = 1 if 3 > 2 else 0 print(a << 3 | 1, a << (3 | 1), 2 + 3 4 2 // 8 % 5)