ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
from math import floor, ceil, trunc print(floor(-0.5), ceil(-0.5), trunc(-0.5), floor(2))
- A. -2 -0 0 2
- B. -1 0 0 2
- C. -1 0 -1 2
- D. -1 0 0 3
Correct answer: B. -1 0 0 2
floor rounds toward negative infinity, so -0.5 becomes -1. ceil rounds toward positive infinity and gives 0 as an int, and trunc drops the fraction, giving 0 as well.
More Python Programming questions
- 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'))
- What is printed? python print(round(1.0000000000000002, 15) == 1, 1.0000000000000002 == 1, 1.0000000000000002 - 1 == 2.220446049250313e-16)