Quiz Space

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

Question 16: What will be the value of the following expression after…

Question 16

+2 marksOne correct option

Consider the below python code.
def categorize_numbers(numbers):
categories = {
"cat_1": set(),
"cat_2": set(),
"cat_3": set()
}
def check(n):
if n % 5 == 0:
return True
return False
for num in numbers:
if num % 2 == 0:
categories["cat_1"].add(num)
else:
categories["cat_2"].add(num)
if check(num):
categories["cat_3"].add(num)
return categories
result = categorize_numbers([
2, 3, 4, 2, 5, 6, 3, 2, 7, 8,
9, 10, 5, 4, 7, 8, 3, 10, 2
])
Based on the given code snippet answer the given subquestions.

What will be the value of the following expression after running the given code snippet?
sorted(result["cat_1"] & result["cat_3"])

  1. A

    [10]

  2. B

    [5]

  3. C

    [2, 4, 5, 6, 8, 10]

  4. D

    [5, 10]

Show answer

Correct answer

  • A

    [10]

Question 16 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 2 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. Q5Given the following code snippet, what will be the output?\ def update_records(records, updates):\ for key, value in up…
  6. Q6Given the following code snippet, what will be the output?\ def get_square(items, i):\ return items[i]2\ def safe_get_s…
  7. 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…
  8. Q8Consider the following snippet of code:\ filename = "test.txt"\ with open(filename, "w") as f:\ f.write("\n".join((f"Li…
  9. Q9Consider the following snippet of code:\ class Shape:\ def init(self):\ pass\ def area(self):\ return "Area not defined…
  10. Q10Consider the below python code.\ lst = []\ for i in range(5):\ lst.append(i)\ lst.append(i10)\ lst[1:4] = [100]\ print(…
  11. Q11Consider the below python code.\ def process_array(arr):\ total = 0\ for i, row in enumerate(arr):\ total += row[i]\ re…
  12. Q12Consider the below python code.\ def procedure(child_dict, i):\ if i not in child_dict.keys():\ return 1\ ans = 1\ for …
  13. Q13Consider the below python code.\ class A:\ def init(self):\ self.value = 5\ def add(self, num):\ self.value += num\ ret…
  14. Q14On executing the given code, how many number of lines will be there in the file example_file.txt ?
  15. Q15What will be printed if we call random_access_read(filename, seek_pos) immediately after running the given code?
  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 ?