ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
print(0.1 * 3, round(0.1 * 3, 2), 1.1 + 2.2 == 3.3, round(1.1 + 2.2, 1) == 3.3)
- A. 0.3 0.3 True True
- B. 0.30000000000000004 0.3 True True
- C. 0.30000000000000004 0.3 False True
- D. 0.3 0.30 False True
Correct answer: C. 0.30000000000000004 0.3 False True
0.1 is not exactly representable in binary, so 0.1 * 3 and 1.1 + 2.2 carry a tiny error and the equality fails; rounding first makes the comparison safe.
More Python Programming questions
- What is printed? python print(round(0.125, 2), round(2.675, 2), round(-1.5), round(25, -1), round(35, -1))
- What is printed? python print(int("٤٢"), "²".isdigit(), "²".isdecimal(), "½".isnumeric(), "4.2".isdigit())
- What is printed? python a = 10 16 print(float(a + 1) == float(a), int(float(2 53 + 1)) - 2 53, 2 53 + 1.0 == 2 53)
- What is printed? python print(divmod(-17, 5), divmod(17, -5), -17 % -5, pow(3, -1, 7))
- What is printed? python print(not 1 == 2, not (1 == 2) is True, (not 1) == 2, 1 + True + True)
- What is printed? python x = 5 print(1 < x < 10 > 3 != 4, 3 > 2 > 1 == True, (3 > 2) > (1 == True), 0 == 0 in [0])