ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 0.1 + 0.2)
- A. False True 0.30000000000000004
- B. True True 0.3
- C. False False 0.3
- D. True False 0.30000000000000004
Correct answer: A. False True 0.30000000000000004
0.1 and 0.2 have no exact binary form, so their sum is 0.30000000000000004. Rounding to 10 places happens to recover 0.3, but the raw comparison is False, which is why floats need a tolerance.
More Python Programming questions
- What is printed? python print(round(2.5), round(3.5), round(-0.5), round(2.675, 2), round(1.005, 2))
- What is printed? python a = float('nan') b = float('nan') print(a == a, a is a, a == b, [a] == [a], [b] == [a])
- What is printed? python print(253 + 1 == 253 + 1.0, 253 + 1 == 253, float(253 + 1) == 253)
- What is printed? python pairs = [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'y')] print(sorted(pairs, key=lambda t: t[0])) print(sorted(pairs…
- What is printed on the second line? python words = ['pear', 'fig', 'apple', 'kiwi', 'date'] print(sorted(words, key=lambda w: (-len(w)…
- What is printed? python print(('ab' 3).count('aba'), 'ababa'.count('aba'), 'aaaa'.count('aa'))