ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(1 / 3 * 3 == 1.0, 2 / 3 * 3 == 2.0, 10 / 3 * 3 == 10.0, 0.7 * 3 == 2.1)
- A. True True True False
- B. True True False False
- C. True False True False
- D. False True True False
Correct answer: A. True True True False
Some products of a division and a multiplication round back exactly, but 0.7 * 3 gives 2.0999999999999996, which is not the nearest double to 2.1.
More Python Programming questions
- What is printed? python print(float('nan') < 1, float('nan') > 1, float('nan') != float('nan'))
- What is printed? python import math print(math.isnan(float('nan') 0), math.isinf(1e308 10), math.isfinite(-0.0), math.copysign(1, -0.0))
- What is printed on the first line? python print(min(0.0, -0.0), max(-0.0, 0.0), min(-0.0, 0.0), -0.0 < 0.0)
- What is printed? python print(sum(i (-1) i for i in range(1, 7)), (-1) 7 + 0.0, (-1.0) 2, (-2) -2)
- What is printed? python def f(n): return sum(d if n % 2 else -d for d in range(1, n + 1)) print(f(1), f(2), f(3), f(4))
- What is printed? python print(int('-0b11', 0), int('01', 0) if False else 0, int('1000'), int(' 0010 '))