ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(round(2.675, 2), round(2.665, 2), round(1.0049999999999999, 3), round(-2.5, 0))
- A. 2.67 2.67 1.005 -2.0
- B. 2.67 2.66 1.005 -2.0
- C. 2.67 2.67 1.004 -2.0
- D. 2.68 2.67 1.005 -3.0
Correct answer: A. 2.67 2.67 1.005 -2.0
Each literal is stored as a double, and the stored value decides the result. 2.675 and 2.665 are both just above their midpoints in binary, so both round to 2.67. Half-to-even sends -2.5 to -2.0.
More Python Programming questions
- What is printed? python print(max('apple', 'banana', key=len), max(['x', 'yy', 'zz'], key=len), min([3, 1, 1.0], key=abs), max([1, 1.0]…
- What is printed? python print(float('0.1') + float('0.2') == 0.3, float('0.30000000000000004') == 0.1 + 0.2…
- What is printed? python s = 'hello' print(s.index('l'), s.rindex('l'), s.find('z'), s.count('l'))
- What is printed? python print(int(str(264) 0 + '7') 2, len(str(7 100)), 7 100 % 10)
- What is printed? python from itertools import product print(list(map(''.join, product('ab', repeat=2))))
- What is printed? python print(sum(range(10 6)) % 1000, sum(range(1, 11)) // 5)