ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(round(1.5, 0), round(-2.5), round(2.5, 0) == 2, round(0.5, 0) == 0)
- A. 2.0 -2 True True
- B. 2 -2 True True
- C. 2.0 -3 True True
- D. 2.0 -2 False True
Correct answer: A. 2.0 -2 True True
round with ndigits=0 on a float returns a float, so 1.5 becomes 2.0. Without ndigits round returns an int, and -2.5 rounds to the even -2. The float 2.0 equals the int 2.
More Python Programming questions
- What is printed? python from math import floor, ceil, trunc print(floor(-0.5), ceil(-0.5), trunc(-0.5), floor(2))
- What is printed? python print(sorted([3, 1, 2], key=lambda x: -x)[0], sorted('bca', key=lambda c: c > 'a'))
- What is printed? python print(int('10', 36) == 36, int('Z', 36), int('z', 36) + 1, int('10', 2) == 2)
- What is printed? python x = [1, 2, 3] print(x.pop(), x.pop(0), x, x.insert(0, 9) or x)
- What is printed? python print(max(map(len, ['a', 'bbb', 'cc'])), min(len(s) for s in ['a', 'bbb']), sum(len(s) for s in ['ab', 'c']))
- What is printed? python print(float('1e2') == 100, int(float('1e2')), str(float('1e2')), int('100'))