Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Quiz 1 · 26 Oct 2025 (Afternoon)
Examination Instructions & Guidelines
- Solve on notebook/paper first before checking solutions.
- MCQ: Exactly 1 option is correct. Negative marking applies.
- MSQ: One or more options correct. Select all to score.
- NAT: Numerical response. No negative marking.
- Scientific calculator allowed for all calculations.
- Official answer key is sealed at the end of this sheet.
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
Q1MCQ3 Marks·Choose one optionConsider the following Python code. What will be the output? s = "programming" print(s[::-1].replace("g", "#"))
- A#nimmarrop#
- B#nimmar#orp
- Cprogrammin#
- Dgni#marropg
- Q2MCQ3 Marks·Choose one option
Consider the following Python code. What will be the output? x, y, z = "", "python", 0 print((x or y) and (z or len(y)))
- A6
- B""
- C"python"
- D0
- ETrue
- Q3MCQ3 Marks·Choose one option
Consider the following python code. What will the value stored in _xat the end of the program execution? x = 5 x = x + 2.0 x = str(x) + "3" x = x * 2 x = [x] x = x + [10]
- A['7.03', '7.03', 10]
- B['7.03', 10]
- C['7.037.03']
- D['7.037.03', 10]
- Q4MCQ4 Marks·Choose one option
You have a list of lists: You want to compute the sum of all even numbers greater than 3. Consider the two code snippets below (with the condition left blank): Snippet-1 s = 0 for row in data: for val in row: __________: s += val print(s) Snippet-2 s = 0 i = 0 while i < len(data): j = 0 while _________: if data[i][j] % 2 == 0 and data[i][j] > 3: s += data[i][j] j += 1 i += 1 print(s) Which of the following conditions, when filled in the blanks in both snippets, will give the correct result?
- ASnippet 1: if element % 2 == 0 and element > 3: Snippet 2: i > len(data[j]
- BSnippet 1: if element % 2 != 0 and element > 3: Snippet 2: i < len(data[j]
- CSnippet 1: if element % 2 == 0 and element > 3: Snippet 2: j < len(data[i]):
- DSnippet 1: if element % 2 == 0 and element < 3: Snippet 2: j > len(data[i]):
- Q5MCQ4 Marks·Choose one option
Assume _s is a _(str) variable. What is the type of the expression "".join(sorted(set(s.lower()))) ?
- Aint
- Bset
- Clist
- Dbool
- Estr
- FNoneType
- GThe code raises an error.
- Q6MSQ4 Marks·Choose all correct options
Consider the following Python code: t = (5, [10, 20], (30, [40, 50],(30,))) Which of the following statements are valid? (Select all that apply)
- At[1].append(25)
- Bt[2] += (60,)
- Ct[2][0] = 35
- Dt[2][2].append(60)
- Et[2][1][0] = 45
- Q7MSQ3 Marks·Choose all correct options
Consider the below code. if x: print('x') else: if y: if z: print('z') print('y') else: print('none') Select the possible output(s) of the given code, assuming any possible values for _x , _y , and _z .
- Ax
- Bz y
- Cx y
- Dnone
- Ex z
- Fy
- Q8NAT4 Marks·Write the number
Consider the following Python code: for i in range(1, 6): for j in range(1, 6): for k in range(1, 2): if i == j: print("-") else: print("*", end=" ") print("+") How many lines will be printed when this code is executed?
Your answer: - Q9NAT3 Marks·Write the number
Consider the following Python code: for i in range(1, 5): for j in range(1, 5): if j == 3: break if i == 2: continue print(i, j) How many lines will be printed when this code is executed?
Your answer: - Q10NAT3 Marks·Write the number
Consider the following Python code: P = {1, 2, 3, 4} Q = {3, 4, 5, 6} R = {4, 5, 6, 7} S = {2, 4, 6, 8} result = ((P | Q) - R) & S print(result) How many elements will be present in result?
Your answer: Read the passage below, then answer Q11–Q12
Consider the following snippet of code and answer the given sub-questions: def analyze(data):
result = []
for item in data:
if isinstance(item, tuple):
total = 0
for x in item:
if x % 2 == 0:
total += x
result.append(total)
elif isinstance(item, int) and item % 2 == 1:
result.append(item * 3)
else:
continue
return result
sample = [(2, 5, 6), 7, (1, 3), 4, (8, 2, 1)]
output = analyze(sample)
Q11MCQ4 Marks·Choose one optionWhat is the value of _(output) after executing the given code?
- A[8, 21, 0, 4, 10]
- B[8, 21, 4, 2, 10]
- C[8, 21, 0, 10]
- D[8, 7, 0, 10]
- Q12NAT4 Marks·Write the number
How many times is the inner _(for x in item:) loop executed in total when running analyze(sample) ?
Your answer: Read the passage below, then answer Q13–Q14
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.
Q13MCQ4 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]]
- Q14MCQ4 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]