ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(0.1 + 0.2 in [0.3], 0.3 in [0.1 + 0.2], round(0.1 + 0.2, 1) in [0.3])
- A. True True False
- B. False False True
- C. False True True
- D. False False False
Correct answer: B. False False True
0.1 + 0.2 is not equal to 0.3 as a float, so both exact membership tests fail. Rounding to one place gives the float 0.3, which is in the list.
More Python Programming questions
- What is printed? python print(1 in {1.0: 'a'}, '1' in {1: 'a'}, 1.0 in {True: 1}, {1, True, 1.0})
- What is printed? python d = {} d[1.0] = 'x' d[1] = 'y' print(d, len(d), d[True])
- What is printed? python print(sorted(['b', 'a', 'c'], key=lambda s: -ord(s)))
- What is printed? python print(sorted([0.5, -0.5, 0, True, False], key=abs))
- What is printed? python print(str(2100)[:5], len(str(2100)), str(2100).count('0'))
- What is printed? python print(int('9' 5) 2 // 109, (109 - 1) 2 // 109)