ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(round(-2.5), round(-3.5), round(7, -1), round(15, -1), round(25, -1))
- A. -3 -4 10 20 30
- B. -2 -4 10 10 20
- C. -2 -3 10 20 20
- D. -2 -4 10 20 20
Correct answer: D. -2 -4 10 20 20
round() with no digits uses half-to-even, so -2.5 becomes -2 and -3.5 becomes -4. For round(x, -1), 15 and 25 are exact halves and go to the even tens, 20 and 20.
More Python Programming questions
- What is printed? python print(int('12abc', 36), int('zz', 36), int('-z', 36))
- What is printed? python print(hash(-1) == hash(-2), hash(-1), hash(261 - 1))
- What is printed? python print(int.bitlength(-255), (255).bitlength(), (256).bitlength())
- What is printed? python print(chr(0x1F600) == '😀', len('😀'), len('😀'.encode('utf-16-le')))
- What is printed? python print(10400 > float('inf'), float('inf') > 10400, float(10308) == 10308)
- What is printed? python print('ab' in ['a', 'ab'], 'ab' in 'a,ab'.split(','), 'a' in 'abc' and 'ac' in 'abc')