ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
print('%.2f' % 1.005, '%.2f' % 1.015, '%.2f' % 1.025, '%.1f' % 0.25)- A. 1.01 1.01 1.03 0.3
- B. 1.00 1.02 1.03 0.2
- C. 1.00 1.01 1.03 0.2
- D. 1.00 1.01 1.02 0.2
Correct answer: D. 1.00 1.01 1.02 0.2
Each decimal is stored just below or at the halfway point, and 0.25 is exact, so it rounds half to even. That gives 1.00, 1.01 and 1.02, and 0.2 for the last one.
More Python Programming questions
- 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))
- What is printed? python print(divmod(-7, 2), divmod(7, -2.0), 7 // -2.0, -7 % 2.5)
- What is printed? python x = -17 print(x // 5, x % 5, divmod(x, -5), x.mod(5))
- What is printed? python print(1018 + 1 == 1000000000000000001, 231 - 1 + 1, -(231), (231) (231) == 262)