Quiz Space

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

Question 13: Consider the below python code.\ class A:\ def init(self…

Question 13

+3 marksNumerical answer

Consider the below python code.
class A:
def __init__(self):
self.value = 5
def add(self, num):
self.value += num
return self.value
class B(A):
def __init__(self):
super().__init__()
self.value *= 2
def add(self, num):
return super().add(num * 2)
obj = B()
result = obj.add(3)
print(result)
What will be the output of the given code?

Show answer

Correct answer: 16

Question 13 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. 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. 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 ?