ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(str(0.1 * 3), repr(0.1 * 3) == '0.30000000000000004', 0.1 * 3 == float(repr(0.1 * 3)))
- A. 0.30000000000000004 True True
- B. 0.3 True True
- C. 0.30000000000000004 False True
- D. 0.30000000000000004 True False
Correct answer: A. 0.30000000000000004 True True
repr gives the shortest decimal string that round-trips to the same float, so converting it back gives the identical value. str and repr agree for floats in Python 3.
More Python Programming questions
- What is printed? python print(10-1 + 10-1 + 10-1 == 0.3, 1/10 + 1/10 + 1/10 == 0.3, 10-1 == 1/10)
- What is printed? python print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1], sorted('cab')[::-1])
- What is printed? python print(int(str(7) 3) 2 % 10, 111 2, (11 2) 10 + 1)
- What is printed? python n = float('nan') print(n in [n], float('nan') in [n], n == n, [n] == [n])
- What is printed? python print(0.1 + 0.2 in [0.3], 0.3 in [0.1 + 0.2], round(0.1 + 0.2, 1) in [0.3])
- What is printed? python print(1 in {1.0: 'a'}, '1' in {1: 'a'}, 1.0 in {True: 1}, {1, True, 1.0})