Variables, Types & Operators · Question 19 · Hard
A float product is compared with 0.3 in two ways. What does this print?
x = 0.1 * 3
print(x == 0.3, abs(x - 0.3) < 1e-9)
- True True
- False False
- True False
- False True
Answer and explanation
Answer: D. False True
Explanation: 0.1 cannot be stored exactly in binary, so 0.1 * 3 is 0.30000000000000004, which is not equal to 0.3. The difference is tiny, far below 1e-9, so the tolerance check is True.
Previous: Five different operators appear in one expression. Following precedence rules… · Next: Three type conversions are printed on one line. What is the output?
Practise variables, types & operators
Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.
More variables, types & operators questions
- Booleans are used in arithmetic here. What does the snippet print?
- Floor division by a float and a remainder with a negative divisor are printed…
- Five different operators appear in one expression. Following precedence rules…
- Three type conversions are printed on one line. What is the output?
More python practice
Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge