ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(round(1234.5678, -2), round(1234.5678, 2), round(-0.0001, 3), round(5.5), round(6.5))
- A. 1200 1234.57 0.0 6 6
- B. 1200.0 1234.57 -0.0 5 6
- C. 1200.0 1234.57 0.0 6 7
- D. 1200.0 1234.57 -0.0 6 6
Correct answer: D. 1200.0 1234.57 -0.0 6 6
round with a negative digit count on a float returns a float, so 1234.5678 becomes 1200.0. Rounding to three places keeps the sign of the small negative value, giving -0.0, while round(5.5) and round(6.5) both go to the even integer 6.
More Python Programming questions
- What is printed? python print(7.0 == 7, (7.0).isinteger(), (7.5).isinteger(), 1e3 == 1000)
- What is printed? python print(2 0.5 2 0.5 == 2, (2 0.5) 2, 2 0.5 2)
- What is printed? python print('%.2f' % 1.005, '%.2f' % 1.015, '%.2f' % 1.025, '%.1f' % 0.25)
- What is printed? python s = 'abc' t = s s += 'd' print(t, s, t is s, id(s) == id(t))
- What is printed? python def tosigned(v): return v - (1 << 32) if v >= 1 << 31 else v print(tosigned(0xFFFFFFFE), tosigned(0x7FFFFFFF)…
- What is printed? python s = 'hello world' print(s.capitalize(), s.title().swapcase(), s.center(15, ''), s.zfill(13))