Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Loops: while, for & nested loops
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
Q1MCQ4 Marks·Choose one optionYou 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]):
- Q2NAT4 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: - Q3NAT3 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:
End Term · 31 Aug 2025 (FN)End Term
- Q4MCQ3 Marks·Choose one option
What will be the total number of lines printed when the following code is executed? scores = { "Aarav": [10, 20, 30], "Bhavna": [15, 25], "Chirag": [12, 18, 24, 30] } round = 0 done = False while not done: done = True for student in scores: if round < len(scores[student]): score = scores[student][round] print( f"Round {round+1}: {student} scored {score}" ) done = False round += 1
- A9
- B8
- C7
- D10
- Q5NAT2 Marks·Write the number
Consider the following Python code: names = ["Aarav", "Bhuvan", "Charan", "Deepa"] marks = [88, 76, 92, 81] bonus = [5, 3, 4, 2] total = 0 for name, mark, extra in zip(names, marks, bonus): if "a" in name.lower(): total += mark + extra else: total += mark print(total) What will be the output of the above code?
Your answer:
End Term · 13 Apr 2025 (FN)End Term
- Q6MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
- Q7NAT3 Marks·Write the number
Your answer:
End Term · 13 Apr 2025 (AN)End Term
- 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: