ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(str(0.5), str(0.25 + 0.125), 0.1 + 0.25)
- A. 0.5 0.375 0.35000000000000003
- B. 0.5 0.375 0.35
- C. 0.5 0.3750 0.35
- D. 0.5 0.375 0.3500000000000001
Correct answer: B. 0.5 0.375 0.35
0.5 and 0.375 are exact in binary, so they print as written. 0.1 + 0.25 rounds to the double whose shortest repr is 0.35.
More Python Programming questions
- What is printed? python s = 'a,b;c' print(s.split(',;'), s.replace(';', ','), s.split(';'))
- What is printed? python print(max(range(5), key=lambda i: (i % 3, -i)))
- What is printed? python print(sum(x x for x in range(-3, 4)), sum(abs(x) for x in range(-3, 4)))
- What is printed? python print(2 0.5 2 0.5 == 2, round(2 0.5 2 0.5, 12) == 2)
- What is printed? python print(''.join(reversed('ab' 2)), 'ab'[::-1] 2 == 'baba')
- Which operation is O(1) on average in CPython?