Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Lists, slicing & matrices
Examination Instructions & Guidelines
- Solve on notebook/paper first before checking solutions.
- MCQ: Exactly 1 option is correct. Negative marking applies.
- NAT: Numerical response. No negative marking.
- Scientific calculator allowed for all calculations.
- Official answer key is sealed at the end of this sheet.
Quiz 1 · 26 Oct 2025 (AN)Quiz 1
Useful Reference Data for this Paper
Useful Information
NAT → integer
For all NAT questions in this exam, the answer will always be an integer and not a float value. If the answer to a question is 18, then just enter that value. Do not enter 18.0
Read the passage below, then answer Q1–Q2
Consider the following code:
def flipper(matrix):
transformed = []
for row in matrix:
new_row = []
for element in row:
if element < 0:
new_row.append(0)
elif element % 2 == 0:
new_row.append(element * 2)
else:
new_row.append(element * 3)
transformed.append(new_row)
result = [
val
for sub in transformed
for val in sub
if val > 5
]
return transformed, result
matrix = [[1, -2, 3], [4, 5, -6], [7, 8]]
out1, out2 = flipper(matrix)
print(out1)
print(out2)
Answer the subquestions based on the given data.
Q1MCQ4 Marks·Choose one optionWhat is the value of _(out1) after executing the code?
- A[[1, -4, 9], [8, 15, -12], [21, 16]]
- B[[3, 0, 9], [8, 15, 0], [21, 16]]
- C[[3, 0, 9], [4, 15, 0], [21, 16]]
- D[[1, 0, 3], [8, 15, 0], [21, 16]]
- Q2MCQ4 Marks·Choose one option
What is the value of _(out2) after executing the code?
- A[3, 9, 8, 15, 21, 16]
- B[9, 8, 15, 21, 16]
- C[8, 15, 21, 16]
- D[3, 0, 9, 8, 15, 0, 21, 16]
End Term · 31 Aug 2025 (FN)End Term
- Q3MCQ3 Marks·Choose one option
What will be the output of the following code? items = ["apple", "banana", "cherry", "date", "fig", "grape", "kiwi"] sliced = items[::2] # Step of 2 filtered = [fruit for fruit in sliced if len(fruit) > 4] result = "_".join(filtered[::-1]) print(result)
- Aapple_cherry
- Bfig_kiwi
- Cgrape_fig
- Dcherry_apple
- Q4NAT3 Marks·Write the number
Consider the following Python code snippet: colors = ['red', 'blue', 'green', 'red', 'blue', 'red', 'yellow'] freq = [colors.count(color) for color in colors] filtered = [f for f in freq if f >= 2] filtered.sort(reverse=True) if filtered: filtered.pop(0) if filtered: filtered.pop(-1) print(len(filtered)) What is the output of the given code?
Your answer:
End Term · 31 Aug 2025 (AN)End Term
- Q5NAT3 Marks·Write the number
Consider the below python code. lst = [] for i in range(5): lst.append(i) lst.append(i*10) lst[1:4] = [100] print(sum(lst)) What will be the output of the given code?
Your answer: - Q6NAT3 Marks·Write the number
Consider the below python code. def process_array(arr): total = 0 for i, row in enumerate(arr): total += row[i] return total array = [] for i in range(5): row = [] for j in range(i + 1): row.append((i + 1) * (j + 1)) array.append(row) print(process_array(array)) What will be the output of the given code?
Your answer:
End Term · 13 Apr 2025 (FN)End Term
- Q7NAT3 Marks·Write the number
Your answer: - Q8NAT3 Marks·Write the number
Your answer:
End Term · 22 Dec 2024 (FN)End Term
- Q9NAT3 Marks·Write the number
Your answer:
End Term · 22 Dec 2024 (AN)End Term
- Q10MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
- Q11NAT3 Marks·Write the number
Your answer: