Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Recursion
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.
End Term · 31 Aug 2025 (FN)End Term
- Q1NAT3 Marks·Write the number
Consider the following Python code: def transform(words): if not words: return [] first = words[0][::-1] if first == first[::-1]: first = "<|>" return [first] + transform(words[1:]) sentence = "refer logic noon stats apple radar" words = sentence.split() new_sentence = " ".join(transform(words)) print(len(new_sentence)) What is the output of the given code?
Your answer:
End Term · 31 Aug 2025 (AN)End Term
- Q2NAT3 Marks·Write the number
Consider the below python code. def procedure(child_dict, i): if i not in child_dict.keys(): return 1 ans = 1 for j in child_dict[i]: ans += procedure(child_dict, j) return ans child_dict = dict() child_dict[0] = [1,2] child_dict[1] = [3,4,5] child_dict[2] = [6,7,8] print(procedure(child_dict,0)) What will be the output of the given code?
Your answer:
End Term · 13 Apr 2025 (FN)End Term
- Q3MCQ3 Marks·Choose one option

- AIt reverses the entire sub-list from left to right, regardless of whether the elements are odd or even.
- BIt reverses only the odd elements in the range [left, right], leaving even elements in their original positions.
- CIt moves all even elements to the left and all odd elements to the right (a partition), but does not change the relative order of the odd elements themselves.
- DIt sorts the sub-list from left to right in ascending order, ignoring whether elements are odd or even.
- Q4NAT4 Marks·Write the number
Your answer:
End Term · 13 Apr 2025 (AN)End Term
- Q5NAT4 Marks·Write the number
Your answer: Read the passage below, then answer Q6–Q8
Based on the below code answer the given subquestions.
Q6NAT1 Mark·Write the number
Your answer:- Q7NAT1.5 Marks·Write the number
Your answer: - Q8NAT1.5 Marks·Write the number
What will be the value passed to the function in the call before the base case, if the function is called with the input 32456 ?
Your answer:
End Term · 22 Dec 2024 (FN)End Term
- Q9MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
Read the passage below, then answer Q10–Q12
Q10MCQ1.5 Marks·Choose one option
- A

- B

- C

- D

- A
- Q11MSQ1.5 Marks·Choose all correct options

- A

- B

- C

- D

- A
- Q12MCQ1 Mark·Choose one option

- A

- B

- C

- D

- A
End Term · 22 Dec 2024 (AN)End Term
Read the passage below, then answer Q13–Q15
Q13MCQ1.5 Marks·Choose one option
- A

- B

- C

- D

- A
- Q14MSQ1.5 Marks·Choose all correct options

- A

- B

- C

- D

- A
- Q15MSQ1 Mark·Choose all correct options

- A

- B

- C

- D

- A