Quiz Space

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

Question 18: Consider the following Python code and answer the sub-qu…

Question 18

+2 marksNumerical answer

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)

What will the output of the given code?

Show answer

Correct answer: 6

Question 18 of 20 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. Q1What will be the output of the following Python code?\ words = ["jacket", "cap", "scarf", "hat", "sock"]\ result = []\ …
  2. Q2Consider the following Python code:\ def evaluate_score(score):\ if score >= 90:\ if score == 100:\ print("Perfect Scor…
  3. Q3Consider the following Python code:\ class Employee:\ def init(self, name):\ self.name = name\ self.role = "Employee"\ …
  4. Q4What will be the total number of lines printed when the following code is executed? scores = {\ "Aarav": [10, 20, 30],\…
  5. Q5What will be the output of the following code snippet?\ data = [(4, 7), (5, 8), (6, 6), (9, 3)]\ total = 0\ for a, b in…
  6. Q6What will be the output of the following code?\ items = ["apple", "banana", "cherry", "date", "fig", "grape", "kiwi"]\ …
  7. Q7Consider the use of the map() function in the following code snippets. Select all options that has the value [4, 9, 16,…
  8. Q8Which of the following statements about the exception handling behavior are TRUE? Select ALL that apply.\ def safe_divi…
  9. Q9Consider the following code snippet:\ def update_scores(scores, bonus):\ updated = []\ for score in scores:\ updated.ap…
  10. Q10Consider the following Python code:\ names = ["Aarav", "Bhuvan", "Charan", "Deepa"]\ marks = [88, 76, 92, 81]\ bonus = …
  11. Q11Consider the following Python code:\ with open("data.txt", "w") as f:\ for i in range(3):\ for j in range(i + 1):\ f.wr…
  12. Q12Consider the following Python code:\ a1 = (3, 6, 9, 12, 15, 18, 21, 24)\ a2 = a1[2:7]\ a3 = a2[::-1]\ a4 = tuple(x for …
  13. Q13Consider the following Python code:\ def transform(words):\ if not words:\ return []\ first = words[0][::-1]\ if first …
  14. Q14Consider the following Python code snippet:\ colors = ['red', 'blue', 'green', 'red', 'blue', 'red', 'yellow']\ freq = …
  15. Q15Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  16. Q16Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  17. Q17Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  18. Q19Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …
  19. Q20Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …