ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(str(round(2.5)), str(round(3.5)), round(2.5 + 0.0001), round(-2.5 - 0.0001))
- A. 2 4 3 -3
- B. 2 4 2 -2
- C. 2 3 3 -3
- D. 3 4 3 -3
Correct answer: A. 2 4 3 -3
round uses half-to-even for exact halves, so 2.5 becomes 2 and 3.5 becomes 4. Adding or subtracting a tiny amount moves the value past the midpoint, so it rounds away from zero.
More Python Programming questions
- What is printed? python s = 'ab' 2 + 'c' print(s.endswith('bc'), s.startswith('ab', 2), s.find('ab', 1), s.count('ab'))
- What is printed? python print(len(''.join(str(i) for i in range(1, 11))), ''.join(str(i) for i in range(1, 11))[-3:], sum(len(str(i)) for…
- What is the time complexity of checking whether a number n is prime by trial division up to its square root?
- What is printed? python from string import Template print(Template('a-b').substitute(a=1, b=2), Template('ac').safesubstitute(a='x')…
- What is printed? python try: print((300).tobytes(1, 'big')) except OverflowError: print('overflow') print((255).tobytes(1, 'big')…
- What is printed? python print(bool('0'), bool(0.0), bool(-0.0), bool(float('nan')), bool(' '))