ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(float('0.1') + float('0.2') == float('0.30000000000000004'), 0.1 + 0.2 == 0.30000000000000004)- A. True True
- B. True False
- C. False True
- D. False False
Correct answer: A. True True
float() and the literal both parse the decimal text to the nearest double, and 0.30000000000000004 is that same double as 0.1 + 0.2. The equality holds because the shortest repr of the sum is that string.
More Python Programming questions
- What is printed? python print(5 // 0.4, 5 % 0.4, 0.4 12 == 4.8, 5 / 0.4)
- 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)])