Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Dictionaries
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
Read the passage below, then answer Q1–Q3
Consider the following Python code and answer the sub-questions:
students = [
{
"name": "Arya",
"subjects": {
"Math": 78, "Science": 88, "English": 92
}
},
{
"name": "Bilal",
"subjects": {
"Math": 65, "Science": 55, "English": 60
}
},
{
"name": "Chitra",
"subjects": {
"Math": 45, "Science": 40, "English": 42
}
},
{
"name": "Deep",
"subjects": {
"Math": 90, "Science": 91, "English": 85
}
},
{
"name": "Esha",
"subjects": {
"Math": 35, "Science": 39, "English": 55
}
},
]
def filter_and_rank(data):
eligible = []
for student in data:
marks = list(student["subjects"].values())
passed = 0
high = 0
for mark in marks:
if mark >= 40:
passed += 1
if mark >= 90:
high += 1
if passed == len(marks) and high > 0:
total = sum(marks)
eligible.append((student["name"], total))
eligible.sort(key=lambda x: x[1], reverse=True)
return [name for name, _ in eligible]
Q1MCQ2 Marks·Choose one optionWhat is the output of filter_and_rank(students) ?
- A['Deep', 'Arya']
- B['Arya', 'Deep']
- C['Deep']
- D['Arya']
- Q2MSQ2 Marks·Choose all correct options
Which of the following students failed to be included due to failing at least one subject?
- ABilal
- BChitra
- CEsha
- DArya
- Q3NAT1 Mark·Write the number
If a new student {"name": "Fatima", "subjects": {"Math": 90, "Science": 90, "English": 90}} is added to the list, what will be the new position (1-based index) of _(Fatima) in the ranked output list returned by _(filter_and_rank) ?
Your answer:
End Term · 31 Aug 2025 (AN)End Term
- Q4MCQ3 Marks·Choose one option
Consider the below code snippet. def updated_val(d, key, val): if key in d: d[key] += val else: d[key] = val return d[key] my_dict = {'a': 2, 'b': 3} print( updated_val(my_dict, 'c', 4) + updated_val(my_dict, 'c', 2) + updated_val(my_dict, 'a', 2) ) What will be the output of the above code
- A6
- B14
- C10
- DRaises KeyError
- Q5MCQ3 Marks·Choose one option
Given the following code snippet, what will be the output? def update_records(records, updates): for key, value in updates.items(): if key in records and isinstance(records[key], dict): for sub_key, sub_val in value.items(): if sub_key in records[key]: records[key][sub_key] += sub_val else: records[key][sub_key] = sub_val else: records[key] = value return records data = { "A": {"x": 10, "y": 20}, "B": {"x": 5, "z": 15}, "C": 100 } updates = { "A": {"x": 5, "z": 5}, "B": {"y": 10}, "C": {"x": 10}, "D": {"w": 7} } result = update_records(data, updates) print(result)
- AA: {'x': 15, 'y': 20, 'z': 5} B: {'x': 5, 'z': 15, 'y': 10} C: {'x': 10} D: {'w': 7}
- BA: {'x': 15, 'y': 20, 'z': 5} B: {'x': 5, 'z': 15, 'y': 10} C: {'x': 110} D: {'w': 7}
- CA: {'x': 5, 'z': 5} B: {'y': 10} C: {'x': 10} D: {'w': 7}
- DA: {'x': 5, 'y': 20, 'z': 5} B: {'x': 5, 'z': 15, 'y': 10} C: 100 D: {'w': 7}
End Term · 13 Apr 2025 (FN)End Term
- Q6MSQ3 Marks·Choose all correct options

- A"debitcard", "badcredit"
- B"admirer", "married"
- C"schoolmaster", "theclassroom"
- D"aabbcc", "abcabc"
End Term · 13 Apr 2025 (AN)End Term
- Q7NAT3 Marks·Write the number
Your answer: - Q8MSQ3 Marks·Choose all correct options

- A"taco cat"
- B"civic room"
- C"racecar"
- D"level up"