uiz Space

May 2025 term · Programming in Python · BSCS1002

Programming in Python End Term: 31 August 2025, Set QDF1 (May 2025 term)

The IIT Madras BS Programming in Python (Python) End Term paper sat on 31 Aug 2025, in the May 2025 term, set QDF1: 20 questions for 50 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
20
Marks
50
Duration
180 min
MCQ
8
MSQ
5
Numerical
7

Updated

Official paper: IIT M FOUNDATION AN EXAM QDF3 31 Aug 2025 · No negative marking.

Question 1

+3 marksOne correct option

What will be the output of the following Python code?
words = ["jacket", "cap", "scarf", "hat", "sock"]
result = []
for idx, word in enumerate(words):
if idx % 2 == 0:
result.append(word[:2].upper() + str(idx))
elif len(word) > 4:
result.append(word[::-1][:3])
else:
result.append("0" + word[-1])
print(result)

  1. A

    ['JA0', 'pa0', 'SC2', 'tah', 'SO4']

  2. B

    ['JA0', '0p', 'SC2', 'tah', 'SO4']

  3. C

    ['JA0', '0p', 'SC2', '0t', 'SO4']

  4. D

    ['JA0', '0p', 'SC2', '0t', '0k']

Show answer

Correct answer

  • C

    ['JA0', '0p', 'SC2', '0t', 'SO4']

Question 2

+3 marksOne correct option

Consider the following Python code:
def evaluate_score(score):
if score >= 90:
if score == 100:
print("Perfect Score")
else:
print("Excellent")
elif score >= 60:
if score >= 80:
print("Very Good")
else:
print("Good")
else:
if score >= 40:
if score % 2 == 0:
print("Needs Improvement")
else:
print("Barely Passed")
else:
print("Fail")
Which of the following inputs will produce the output Needs Improvement ?

  1. A

    42

  2. B

    47

  3. C

    39

  4. D

    60

Show answer

Correct answer

  • A

    42

Question 3

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

  1. A

    Ananya 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

  2. B

    Ananya 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

  3. C

    Ananya works as Developer
    Rajeev works as Manager
    Kiran works as Developer

  4. D

    Developer
    Employee
    Manager
    Employee
    Developer
    Employee

Show answer

Correct answer

  • A

    Ananya 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

Question 4

+3 marksOne correct option

What will be the total number of lines printed when the following code is executed? scores = {
"Aarav": [10, 20, 30],
"Bhavna": [15, 25],
"Chirag": [12, 18, 24, 30]
}
round = 0
done = False
while not done:
done = True
for student in scores:
if round < len(scores[student]):
score = scores[student][round]
print(
f"Round {round+1}: {student} scored {score}"
)
done = False
round += 1

  1. A

    9

  2. B

    8

  3. C

    7

  4. D

    10

Show answer

Correct answer

  • A

    9

Question 5

+3 marksOne correct option

What will be the output of the following code snippet?
data = [(4, 7), (5, 8), (6, 6), (9, 3)]
total = 0
for a, b in data:
if a % 2 == 0:
if a < b:
total += (b - a)
elif a == b:
total += a + b
else:
total += (a * b) % 4
else:
if b % 2 == 0:
total += b
else:
total -= a
print(total)

  1. A

    30

  2. B

    14

  3. C

    16

  4. D

    6

Show answer

Correct answer

  • B

    14

Question 6

+3 marksOne correct option

What will be the output of the following code?
items = ["apple", "banana", "cherry", "date", "fig", "grape", "kiwi"]
sliced = items[::2] # Step of 2
filtered = [fruit for fruit in sliced if len(fruit) > 4]
result = "_".join(filtered[::-1])
print(result)

  1. A

    apple_cherry

  2. B

    fig_kiwi

  3. C

    grape_fig

  4. D

    cherry_apple

Show answer

Correct answer

  • D

    cherry_apple

Question 7

+3 marksOne or more correct options

Consider the use of the map() function in the following code snippets. Select all options that has the value [4, 9, 16, 25] in the variable squares after execution.

Select all that apply.

  1. A

    nums = [2, 3, 4, 5]
    squares = list(map(lambda x: x**2, nums))

  2. B

    nums = [4, 9, 16, 25]
    squares = map(int, nums)

  3. C

    nums = [2, 3, 4, 5]
    def square(n):
    return n * n
    squares = list(map(square, nums))

  4. D

    nums = [2, 3, 4, 5]
    squares = []
    for x in nums:
    squares.append(x ** 2)

  5. E

    nums = [2, 3, 4, 5]
    squares = list(map(pow, nums, [2]*4))

Show answer

Correct answers

  • A

    nums = [2, 3, 4, 5]
    squares = list(map(lambda x: x**2, nums))

  • C

    nums = [2, 3, 4, 5]
    def square(n):
    return n * n
    squares = list(map(square, nums))

  • D

    nums = [2, 3, 4, 5]
    squares = []
    for x in nums:
    squares.append(x ** 2)

  • E

    nums = [2, 3, 4, 5]
    squares = list(map(pow, nums, [2]*4))

Question 8

+3 marksOne or more correct options

Which of the following statements about the exception handling behavior are TRUE? Select ALL that apply.
def safe_divide(x, y):
result = []
try:
result.append("Trying division")
result.append(x // y)
except ZeroDivisionError:
result.append("Division by zero")
else:
result.append("No exception occurred")
finally:
result.append("Cleanup done")
return result
output = safe_divide(10, 0)
print(output)

Select all that apply.

  1. A

    The output will contain the string "Trying division"

  2. B

    The string "Division by zero" will appear in the output

  3. C

    The division result will be appended to the output

  4. D

    The string "Cleanup done" will always appear regardless of exceptions

Show answer

Correct answers

  • A

    The output will contain the string "Trying division"

  • B

    The string "Division by zero" will appear in the output

  • D

    The string "Cleanup done" will always appear regardless of exceptions

Question 9

+3 marksOne or more correct options

Consider the following code snippet:
def update_scores(scores, bonus):
updated = []
for score in scores:
updated.append(score + bonus)
return updated
original_scores = [10, 20, 30]
new_scores = update_scores(original_scores, 5)
Which of the following statements are TRUE?

Select all that apply.

  1. A

    The list original_scores remains unchanged after calling update_scores

  2. B

    The function update_scores returns a new list

  3. C

    The variable score inside the function is local to the function

  4. D

    The function modifies the scores list in place

Show answer

Correct answers

  • A

    The list original_scores remains unchanged after calling update_scores

  • B

    The function update_scores returns a new list

  • C

    The variable score inside the function is local to the function

Question 10

+2 marksNumerical answer

Consider the following Python code:
names = ["Aarav", "Bhuvan", "Charan", "Deepa"]
marks = [88, 76, 92, 81]
bonus = [5, 3, 4, 2]
total = 0
for name, mark, extra in zip(names, marks, bonus):
if "a" in name.lower():
total += mark + extra
else:
total += mark
print(total)
What will be the output of the above code?

Show answer

Correct answer: 351

Question 11

+2 marksNumerical answer

Consider the following Python code:
with open("data.txt", "w") as f:
for i in range(3):
for j in range(i + 1):
f.write(f"Line {i}-{j}" + ("\n" * (j + 1)))
with open("data.txt", "r") as f:
count = len(f.readlines())
print(count)
What is the output of the given code?

Show answer

Correct answer: 10

Question 12

+3 marksNumerical answer

Consider the following Python code:
a1 = (3, 6, 9, 12, 15, 18, 21, 24)
a2 = a1[2:7]
a3 = a2[::-1]
a4 = tuple(x for x in a3 if x % 6 != 0)
a5 = a4[1::2]
ans = sum(a5) + len(a4)
print(ans)
What is the output of the given code?

Show answer

Correct answer: 18

Question 13

+3 marksNumerical answer

Consider the following Python code:
def transform(words):
if not words:
return []
first = words[0][::-1]
if first == first[::-1]:
first = "<|>"
return [first] + transform(words[1:])
sentence = "refer logic noon stats apple radar"
words = sentence.split()
new_sentence = " ".join(transform(words))
print(len(new_sentence))
What is the output of the given code?

Show answer

Correct answer: 27

Question 14

+3 marksNumerical answer

Consider the following Python code snippet:
colors = ['red', 'blue', 'green', 'red', 'blue', 'red', 'yellow']
freq = [colors.count(color) for color in colors]
filtered = [f for f in freq if f >= 2]
filtered.sort(reverse=True)
if filtered:
filtered.pop(0)
if filtered:
filtered.pop(-1)
print(len(filtered))
What is the output of the given code?

Show answer

Correct answer: 3

Question 15

+2 marksOne correct option

Consider the following Python code and answer the sub-questions:
students = [
{
"name": "Arya",
"subjects": {
"Math": 78, "Science": 88, "English": 92
}
},
{
"name": "Bilal",
"subjects": {
"Math": 65, "Science": 55, "English": 60
}
},
{
"name": "Chitra",
"subjects": {
"Math": 45, "Science": 40, "English": 42
}
},
{
"name": "Deep",
"subjects": {
"Math": 90, "Science": 91, "English": 85
}
},
{
"name": "Esha",
"subjects": {
"Math": 35, "Science": 39, "English": 55
}
},
]
def filter_and_rank(data):
eligible = []
for student in data:
marks = list(student["subjects"].values())
passed = 0
high = 0
for mark in marks:
if mark >= 40:
passed += 1
if mark >= 90:
high += 1
if passed == len(marks) and high > 0:
total = sum(marks)
eligible.append((student["name"], total))
eligible.sort(key=lambda x: x[1], reverse=True)
return [name for name, _ in eligible]

What is the output of filter_and_rank(students) ?

  1. A

    ['Deep', 'Arya']

  2. B

    ['Arya', 'Deep']

  3. C

    ['Deep']

  4. D

    ['Arya']

Show answer

Correct answer

  • A

    ['Deep', 'Arya']

Question 16

+2 marksOne or more correct options

Consider the following Python code and answer the sub-questions:
students = [
{
"name": "Arya",
"subjects": {
"Math": 78, "Science": 88, "English": 92
}
},
{
"name": "Bilal",
"subjects": {
"Math": 65, "Science": 55, "English": 60
}
},
{
"name": "Chitra",
"subjects": {
"Math": 45, "Science": 40, "English": 42
}
},
{
"name": "Deep",
"subjects": {
"Math": 90, "Science": 91, "English": 85
}
},
{
"name": "Esha",
"subjects": {
"Math": 35, "Science": 39, "English": 55
}
},
]
def filter_and_rank(data):
eligible = []
for student in data:
marks = list(student["subjects"].values())
passed = 0
high = 0
for mark in marks:
if mark >= 40:
passed += 1
if mark >= 90:
high += 1
if passed == len(marks) and high > 0:
total = sum(marks)
eligible.append((student["name"], total))
eligible.sort(key=lambda x: x[1], reverse=True)
return [name for name, _ in eligible]

Which of the following students failed to be included due to failing at least one subject?

Select all that apply.

  1. A

    Bilal

  2. B

    Chitra

  3. C

    Esha

  4. D

    Arya

Show answer

Correct answers

  • B

    Chitra

  • C

    Esha

Question 17

+1 markNumerical answer

Consider the following Python code and answer the sub-questions:
students = [
{
"name": "Arya",
"subjects": {
"Math": 78, "Science": 88, "English": 92
}
},
{
"name": "Bilal",
"subjects": {
"Math": 65, "Science": 55, "English": 60
}
},
{
"name": "Chitra",
"subjects": {
"Math": 45, "Science": 40, "English": 42
}
},
{
"name": "Deep",
"subjects": {
"Math": 90, "Science": 91, "English": 85
}
},
{
"name": "Esha",
"subjects": {
"Math": 35, "Science": 39, "English": 55
}
},
]
def filter_and_rank(data):
eligible = []
for student in data:
marks = list(student["subjects"].values())
passed = 0
high = 0
for mark in marks:
if mark >= 40:
passed += 1
if mark >= 90:
high += 1
if passed == len(marks) and high > 0:
total = sum(marks)
eligible.append((student["name"], total))
eligible.sort(key=lambda x: x[1], reverse=True)
return [name for name, _ in eligible]

If a new student {"name": "Fatima", "subjects": {"Math": 90, "Science": 90, "English": 90}} is added to the list, what will be the new position (1-based index) of Fatima in the ranked output list returned by filter_and_rank ?

Show answer

Correct answer: 1

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 19

+2 marksOne or more correct options

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)

Which of the following are correct?

Select all that apply.

  1. A

    ElectricVehicle.ev_count is 3

  2. B

    PetrolVehicle.pv_count is 2

  3. C

    "Mahindra e2o" is in low_battery_models

  4. D

    Vehicle.get_total() will raise an error

Show answer

Correct answers

  • A

    ElectricVehicle.ev_count is 3

  • B

    PetrolVehicle.pv_count is 2

  • C

    "Mahindra e2o" is in low_battery_models

Question 20

+1 markOne correct option

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 does fleet[1].get_info() return?

  1. A

    Model: Mahindra e2o, Battery: 35%, Status: Low

  2. B

    Model: Mahindra e2o, Fuel: 35L

  3. C

    Model: Mahindra e2o

  4. D

    Model: Mahindra e2o, Battery: 35%

Show answer

Correct answer

  • A

    Model: Mahindra e2o, Battery: 35%, Status: Low