ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print('%.2f' % 1.255, '%.2f' % 1.245, '%.1f' % 0.05, '%.1f' % 0.15)- A. 1.26 1.25 0.1 0.2
- B. 1.25 1.24 0.1 0.2
- C. 1.25 1.25 0.1 0.1
- D. 1.25 1.25 0.0 0.1
Correct answer: C. 1.25 1.25 0.1 0.1
Each literal is stored as a double, and the stored value decides the result. 1.255 and 1.245 are both slightly off their midpoints in binary, and 0.05 and 0.15 round down in the same way.
More Python Programming questions
- What is printed? python print(str(1e-4), str(1e-5), str(123456789.0), str(1234567890123456789.0))
- What is printed? python print(18 // 4 if False else 'na', 'na' 2 + 'ba')
- What is printed? python print(all(c.islower() for c in 'abc'), any(c.isdigit() for c in 'abc'), 'abc'.isascii() and 'é'.isascii())
- What is printed? python from collections import deque d = deque('abc') d.rotate(1) d.appendleft('z') print(''.join(d), d.pop())
- What is printed? python print(len(bin(255)), bin(255).count('0'), bin(-255).count('1'))
- What is printed? python print('%s' % 'x' 3, '%s' 2 % ('a', 'b'), '%s' % ('x' 3))