ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
import math print(math.floor(-0.5), math.ceil(-0.5), math.trunc(-0.5), math.floor(2.999999999999999999))
- A. -1 0 0 2
- B. -1 -1 0 3
- C. 0 0 0 3
- D. -1 0 0 3
Correct answer: D. -1 0 0 3
floor rounds down to -1, while ceil of -0.5 is the integer 0 because ints have no negative zero. The literal 2.999999999999999999 is the double 3.0, so floor gives 3.
More Python Programming questions
- What is printed? python print(f'{1234567.891:.2f}', f'{255:#x}', f'{5:03d}', f'{-5:03d}', f'{-5:+04d}')
- What is printed? python print(str(-0), int('-0'), -0.0 == 0, str(-0.0), 0 -1.0)
- What is printed? python print(str(1e21), str(1e15), str(123456789.123), 1e21 == 1021, float(1021) == 1e21)
- What is printed? python print(str(1e-5), 0.0001, 0.00001, 1e-4 == 0.0001, 10 -4)
- What is printed? python print(sorted(['10', '9', '2b', '2a']), sorted([10, 9, 2], key=str))
- What is printed on the last line? python try: sorted([1, '2']) except TypeError: print('TypeError') print(sorted([1, '2'], key=str))