ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(5 // 0.4, 5 % 0.4, 0.4 * 12 == 4.8, 5 / 0.4)
- A. 12.0 0.2 False 12.5
- B. 12.0 0.19999999999999973 False 12.5
- C. 12.0 0.19999999999999973 True 12.5
- D. 11.0 0.19999999999999973 False 12.5
Correct answer: B. 12.0 0.19999999999999973 False 12.5
0.4 is stored slightly above the decimal value, so 5 // 0.4 is 12.0 and the remainder is a little under 0.2. Multiplying 0.4 by 12 misses 4.8 exactly.
More Python Programming questions
- What is the time complexity of s[::-1] for a string of length n in CPython?
- Which call builds one string from n pieces in O(total length) time?
- Which statement about sorting in Python is correct?
- What is printed? python print(oct(-8), hex(-255), bin(0), format(-5, 'b'))
- What is printed? python n = 13 print(n ^ (n >> 1), [bin(i ^ (i >> 1)) for i in range(4)])
- What is printed? python print(~5 == -6, ~(-5) == 4, (-5) >> 1 == -2, -5 // 2 == -3)