ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import math print(math.floor(-2.5), math.ceil(-2.5), math.trunc(-2.5), int(-2.5))
- A. -3 -2 -3 -2
- B. -3 -3 -2 -2
- C. -3 -2 -2 -2
- D. -2 -2 -2 -2
Correct answer: C. -3 -2 -2 -2
floor goes down to -3 and ceil goes up to -2. trunc and int both round toward zero, giving -2.
More Python Programming questions
- What is printed? python x = 'xyz' print(f'{x!r:>7}|{len(x):03d}|{x[::-1]:^5}|')
- What is printed? python from itertools import chain print(list(chain.fromiterable(['ab', 'c'])), ''.join(chain([['x'], ['y', 'z']])))
- What is printed? python print(repr("it's"), repr('say "hi"'), len('x41101'), len(r'n'))
- What is printed? python print(pow(3, -1, 8)) try: print(pow(4, -1, 8)) except ValueError: print('not invertible')
- What is printed? python import math print(math.comb(100, 50) % 1000, 2100 % 9, sum(map(int, str(2100))) % 9)
- What is printed? python print(5e-324 / 2 == 0, 2e-323 > 5e-324, float('1e-400'), 5e-324 / 2 == 0.0)