ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(len(set(str(i * i) for i in range(10))), sorted([(-1) ** i * i for i in range(6)]))
- A. 9 [-5, -3, -1, 0, 2, 4]
- B. 10 [-4, -2, 0, 1, 3, 5]
- C. 10 [-5, -3, -1, 0, 2, 4, 0]
- D. 10 [-5, -3, -1, 0, 2, 4]
Correct answer: D. 10 [-5, -3, -1, 0, 2, 4]
The squares of 0 to 9 give ten distinct strings. The terms (-1)**i * i are 0, -1, 2, -3, 4, -5, which sorts to [-5, -3, -1, 0, 2, 4].
More Python Programming questions
- What is printed? python print(list(map(round, [0.5, 1.5, 2.5, -0.5, -1.5])), list(map(int, [0.5, 1.5, 2.5, -0.5, -1.5])))
- What is printed? python print(max(['10', '9']), max(['10', '9'], key=len), sorted(['10', '9', '100'], key=lambda s: (len(s), s)))
- What is printed? python print(int(True) - ~True, 4 >> True, True << 3, True + True True)
- What is printed? python print('5' 3 > '10' 2, 5 3 > 10 2, '55' < '9', 55 < 9)
- What is printed? python print(float('inf') > 21000, -float('inf') < -(21000), float('inf') == float('inf') + 1)
- What is printed? python print(repr(0.1), repr(1 / 3), repr(2 / 3), repr(1e-7), repr(100.0))