Quiz Space

Programming in Python · End Term · 31 Aug 2025 · May 2025 term · Set QDF3

Question 5: Given the following code snippet, what will be the output…

Question 5

+3 marksOne correct 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)

  1. A

    A: {'x': 15, 'y': 20, 'z': 5}
    B: {'x': 5, 'z': 15, 'y': 10}
    C: {'x': 10}
    D: {'w': 7}

  2. B

    A: {'x': 15, 'y': 20, 'z': 5}
    B: {'x': 5, 'z': 15, 'y': 10}
    C: {'x': 110}
    D: {'w': 7}

  3. C

    A: {'x': 5, 'z': 5}
    B: {'y': 10}
    C: {'x': 10}
    D: {'w': 7}

  4. D

    A: {'x': 5, 'y': 20, 'z': 5}
    B: {'x': 5, 'z': 15, 'y': 10}
    C: 100
    D: {'w': 7}

Show answer

Correct answer

  • A

    A: {'x': 15, 'y': 20, 'z': 5}
    B: {'x': 5, 'z': 15, 'y': 10}
    C: {'x': 10}
    D: {'w': 7}

Question 5 of 18 in the IIT Madras BS Programming in Python (Python) End Term paper sat on 31 Aug 2025, in the May 2025 term (IIT M FOUNDATION AN EXAM QDF3 31 Aug 2025). It carries 3 marks.

More questions from this paper

  1. Q1Given the following code snippet, what will be the output?\ if None:\ print("None is True")\ elif 0:\ print("0 is True"…
  2. Q2Consider the below code snippet.\ def updated_val(d, key, val):\ if key in d:\ d[key] += val\ else:\ d[key] = val\ retu…
  3. Q3Given the following code snippet, what will be the output?\ a = (1, 2)\ b = (3, 4)\ c = ((5, 6),)\ d = a + b + c\ e = d…
  4. Q4Consider the below output.\ 1 4 7\ 2 5 8\ 3 6 9\ Select the code snippet that will generate the above output.
  5. Q6Given the following code snippet, what will be the output?\ def get_square(items, i):\ return items[i]2\ def safe_get_s…
  6. Q7Consider the following snippet of code:\ t1 = (1, 2, 3)\ t2 = (4, 5, 6)\ t3 = t1 + t2\ t4 = (t1, t2)\ print(t3[2:5])\ p…
  7. Q8Consider the following snippet of code:\ filename = "test.txt"\ with open(filename, "w") as f:\ f.write("\n".join((f"Li…
  8. Q9Consider the following snippet of code:\ class Shape:\ def init(self):\ pass\ def area(self):\ return "Area not defined…
  9. Q10Consider the below python code.\ lst = []\ for i in range(5):\ lst.append(i)\ lst.append(i10)\ lst[1:4] = [100]\ print(…
  10. Q11Consider the below python code.\ def process_array(arr):\ total = 0\ for i, row in enumerate(arr):\ total += row[i]\ re…
  11. Q12Consider the below python code.\ def procedure(child_dict, i):\ if i not in child_dict.keys():\ return 1\ ans = 1\ for …
  12. Q13Consider the below python code.\ class A:\ def init(self):\ self.value = 5\ def add(self, num):\ self.value += num\ ret…
  13. Q14On executing the given code, how many number of lines will be there in the file example_file.txt ?
  14. Q15What will be printed if we call random_access_read(filename, seek_pos) immediately after running the given code?
  15. Q16What will be the value of the following expression after running the given code snippet?\ sorted(result["cat_1"] \& res…
  16. Q17What will be the value of the following expression after running the given code snippet?\ len(result["cat_1"] | result[…
  17. Q18If result = categorize_numbers([1, 2, 10, 15, 20]) , which of the following expression(s) would be evaluated as True ?