Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Classes, objects & inheritance
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
- Q1MCQ3 Marks·Choose one option
Consider the following Python code: class Employee: def __init__(self, name): self.name = name self.role = "Employee" def show_details(self): print(f"{self.name} works as {self.role}") class Developer(Employee): def __init__(self, name): super().__init__(name) self.role = "Developer" def show_details(self): print(f"{self.name} writes code as a {self.role}") super().show_details() class Manager(Employee): def __init__(self, name): super().__init__(name) self.role = "Manager" def show_details(self): print(f"{self.name} manages tasks as a {self.role}") super().show_details() employees = [ Developer("Ananya"), Manager("Rajeev"), Developer("Kiran") ] for emp in employees: emp.show_details() What will be the output of the code above?
- AAnanya writes code as a Developer Ananya works as Developer Rajeev manages tasks as a Manager Rajeev works as Manager Kiran writes code as a Developer Kiran works as Developer
- BAnanya writes code as a Developer Ananya works as Employee Rajeev manages tasks as a Manager Rajeev works as Employee Kiran writes code as a Developer Kiran works as Employee
- CAnanya works as Developer Rajeev works as Manager Kiran works as Developer
- DDeveloper Employee Manager Employee Developer Employee
Read the passage below, then answer Q2–Q4
Consider the following Python code and answer the sub-questions:
class Vehicle:
total_vehicles = 0
all_models = []
def __init__(self, model):
self.model = model
Vehicle.total_vehicles += 1
Vehicle.all_models.append(model)
def get_info(self):
return "Model: " + self.model
def get_total():
return Vehicle.total_vehicles
def count_models_starting_with(letter):
count = 0
for m in Vehicle.all_models:
if m.startswith(letter):
count += 1
return count
class ElectricVehicle(Vehicle):
ev_count = 0
def __init__(self, model, battery):
Vehicle.__init__(self, model)
self.battery = battery
ElectricVehicle.ev_count += 1
if battery < 40:
self.status = "Low"
else:
self.status = "OK"
def get_info(self):
return (
f"{Vehicle.get_info(self)}, "
f"Battery: {self.battery})%, "
f"Status: {self.status}"
)
class PetrolVehicle(Vehicle):
pv_count = 0
def __init__(self, model, fuel):
Vehicle.__init__(self, model)
self.fuel = fuel
PetrolVehicle.pv_count += 1
def get_info(self):
return f"{Vehicle.get_info(self)}, Fuel: {self.fuel} L"
fleet = [
ElectricVehicle("Tesla Model 3", 75),
ElectricVehicle("Mahindra e2o", 35),
PetrolVehicle("Hyundai i10", 20),
PetrolVehicle("Swift", 12),
ElectricVehicle("Tata Tigor EV", 80),
Vehicle("Generic Cycle")
]
low_battery_models = []
for v in fleet:
if isinstance(v, ElectricVehicle):
if v.status == "Low":
low_battery_models.append(v.model)
count = 0
for v in fleet:
if isinstance(v, Vehicle):
count += 1
print(count)
Q2NAT2 Marks·Write the numberWhat will the output of the given code?
Your answer:- Q3MSQ2 Marks·Choose all correct options
Which of the following are correct?
- AElectricVehicle.ev_count is 3
- BPetrolVehicle.pv_count is 2
- C"Mahindra e2o" is in low_battery_models
- DVehicle.get_total() will raise an error
- Q4MCQ1 Mark·Choose one option
What does fleet[1].get_info() return?
- AModel: Mahindra e2o, Battery: 35%, Status: Low
- BModel: Mahindra e2o, Fuel: 35L
- CModel: Mahindra e2o
- DModel: Mahindra e2o, Battery: 35%
End Term · 31 Aug 2025 (AN)End Term
- Q5MCQ3 Marks·Choose one option
Consider the following snippet of code: class Shape: def __init__(self): pass def area(self): return "Area not defined" def describe(self): return f"I am a shape. Area: {self.area()}" class Rectangle(Shape): def __init__(self, width, height): self.width = width self.height = height def area(self): return self.width * self.height class Circle(Shape): def __init__(self, radius): self.radius = radius r = Rectangle(4, 5) c = Circle(3) print(r.describe()) print(c.describe()) What will be the output?
- AI am a shape. Area: 20 I am a shape. Area: Area not defined
- BI am a shape. Area: Area not defined I am a shape. Area: Area not defined
- CAttributeError: 'Rectangle' object has no attribute 'describe'
- DNameError: describe is not defined
- EI am a shape. Area: 20 I am a shape. Area: 28.26
- Q6NAT3 Marks·Write the number
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?
Your answer:
End Term · 13 Apr 2025 (FN)End Term
- Q7MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
Read the passage below, then answer Q8–Q9

Based on the above data, answer the given subquestions.
Q8MCQ1.5 Marks·Choose one optionWhat will be the output of the given code?
- AEmployee Name: Alice Salary: 75000
- BEmployee Name: Alice Salary: 80000 Manager of Department: HR
- CEmployee Name: Alice Salary: 80000
- DManager of Department: HR
- Q9NAT1.5 Marks·Write the number
If the below main code is executed after the class definition, what will be the output?
Your answer:
End Term · 13 Apr 2025 (AN)End Term
- Q10MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
Read the passage below, then answer Q11–Q12
Based on the below data answer the given subquestions.
Q11MSQ1.5 Marks·Choose all correct optionsWhich of the following statements about method overriding in PrimeProduct is true?
- A

- B

- C

- D

- A
- Q12MCQ1.5 Marks·Choose one option

- A1
- B2
- C3
- DCannot be determined
End Term · 22 Dec 2024 (FN)End Term
- Q13MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
End Term · 22 Dec 2024 (AN)End Term
- Q14MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A