ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
print(sum(range(1, 10, 2)), list(range(5))[-1:-4:-1])
- A. 25 [4, 3, 2]
- B. 20 [4, 3, 2]
- C. 25 [4, 3, 2, 1]
- D. 25 [3, 2, 1]
Correct answer: A. 25 [4, 3, 2]
range(1, 10, 2) is 1, 3, 5, 7, 9, which sums to 25. The slice [-1:-4:-1] starts at the last element (4) and steps back, stopping before index -4 (which is 1): [4, 3, 2].
More Python Programming questions
- What is printed? python print("abc" < "abd" < "ab", "10" < "9", 10 < 9)
- What is printed? python print({x % 3: x for x in range(7)})
- What is printed? python print([(i, j) for i in range(3) for j in range(i)])
- What is printed? python def g(): x = yield 1 yield x 2 it = g() print(next(it), it.send(5))
- What is printed? python calls = 0 def f(n): global calls calls += 1 return 1 if n <= 1 else f(n - 1) + f(n - 2) print(f(5), calls)
- What is printed? python import copy a = [[1, 2], [3]] b = copy.copy(a) c = copy.deepcopy(a) a[0].append(9) a.append([4]) print(len(b)…