Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
All 2025 papers
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.
Quiz 1 · 26 Oct 2025 (AN)Quiz 1
Useful Reference Data for this Paper
Useful Information
NAT → integer
For all NAT questions in this exam, the answer will always be an integer and not a float value. If the answer to a question is 18, then just enter that value. Do not enter 18.0
Q1MCQ3 Marks·Choose one optionConsider the following Python code. What will be the output? s = "programming" print(s[::-1].replace("g", "#"))
- A#nimmarrop#
- B#nimmar#orp
- Cprogrammin#
- Dgni#marropg
- Q2MCQ3 Marks·Choose one option
Consider the following Python code. What will be the output? x, y, z = "", "python", 0 print((x or y) and (z or len(y)))
- A6
- B""
- C"python"
- D0
- ETrue
- Q3MCQ3 Marks·Choose one option
Consider the following python code. What will the value stored in _xat the end of the program execution? x = 5 x = x + 2.0 x = str(x) + "3" x = x * 2 x = [x] x = x + [10]
- A['7.03', '7.03', 10]
- B['7.03', 10]
- C['7.037.03']
- D['7.037.03', 10]
- Q4MCQ4 Marks·Choose one option
You have a list of lists: You want to compute the sum of all even numbers greater than 3. Consider the two code snippets below (with the condition left blank): Snippet-1 s = 0 for row in data: for val in row: __________: s += val print(s) Snippet-2 s = 0 i = 0 while i < len(data): j = 0 while _________: if data[i][j] % 2 == 0 and data[i][j] > 3: s += data[i][j] j += 1 i += 1 print(s) Which of the following conditions, when filled in the blanks in both snippets, will give the correct result?
- ASnippet 1: if element % 2 == 0 and element > 3: Snippet 2: i > len(data[j]
- BSnippet 1: if element % 2 != 0 and element > 3: Snippet 2: i < len(data[j]
- CSnippet 1: if element % 2 == 0 and element > 3: Snippet 2: j < len(data[i]):
- DSnippet 1: if element % 2 == 0 and element < 3: Snippet 2: j > len(data[i]):
- Q5MCQ4 Marks·Choose one option
Assume _s is a _(str) variable. What is the type of the expression "".join(sorted(set(s.lower()))) ?
- Aint
- Bset
- Clist
- Dbool
- Estr
- FNoneType
- GThe code raises an error.
- Q6MSQ4 Marks·Choose all correct options
Consider the following Python code: t = (5, [10, 20], (30, [40, 50],(30,))) Which of the following statements are valid? (Select all that apply)
- At[1].append(25)
- Bt[2] += (60,)
- Ct[2][0] = 35
- Dt[2][2].append(60)
- Et[2][1][0] = 45
- Q7MSQ3 Marks·Choose all correct options
Consider the below code. if x: print('x') else: if y: if z: print('z') print('y') else: print('none') Select the possible output(s) of the given code, assuming any possible values for _x , _y , and _z .
- Ax
- Bz y
- Cx y
- Dnone
- Ex z
- Fy
- Q8NAT4 Marks·Write the number
Consider the following Python code: for i in range(1, 6): for j in range(1, 6): for k in range(1, 2): if i == j: print("-") else: print("*", end=" ") print("+") How many lines will be printed when this code is executed?
Your answer: - Q9NAT3 Marks·Write the number
Consider the following Python code: for i in range(1, 5): for j in range(1, 5): if j == 3: break if i == 2: continue print(i, j) How many lines will be printed when this code is executed?
Your answer: - Q10NAT3 Marks·Write the number
Consider the following Python code: P = {1, 2, 3, 4} Q = {3, 4, 5, 6} R = {4, 5, 6, 7} S = {2, 4, 6, 8} result = ((P | Q) - R) & S print(result) How many elements will be present in result?
Your answer: Read the passage below, then answer Q11–Q12
Consider the following snippet of code and answer the given sub-questions: def analyze(data):
result = []
for item in data:
if isinstance(item, tuple):
total = 0
for x in item:
if x % 2 == 0:
total += x
result.append(total)
elif isinstance(item, int) and item % 2 == 1:
result.append(item * 3)
else:
continue
return result
sample = [(2, 5, 6), 7, (1, 3), 4, (8, 2, 1)]
output = analyze(sample)
Q11MCQ4 Marks·Choose one optionWhat is the value of _(output) after executing the given code?
- A[8, 21, 0, 4, 10]
- B[8, 21, 4, 2, 10]
- C[8, 21, 0, 10]
- D[8, 7, 0, 10]
- Q12NAT4 Marks·Write the number
How many times is the inner _(for x in item:) loop executed in total when running analyze(sample) ?
Your answer: Read the passage below, then answer Q13–Q14
Consider the following code:
def flipper(matrix):
transformed = []
for row in matrix:
new_row = []
for element in row:
if element < 0:
new_row.append(0)
elif element % 2 == 0:
new_row.append(element * 2)
else:
new_row.append(element * 3)
transformed.append(new_row)
result = [
val
for sub in transformed
for val in sub
if val > 5
]
return transformed, result
matrix = [[1, -2, 3], [4, 5, -6], [7, 8]]
out1, out2 = flipper(matrix)
print(out1)
print(out2)
Answer the subquestions based on the given data.
Q13MCQ4 Marks·Choose one optionWhat is the value of _(out1) after executing the code?
- A[[1, -4, 9], [8, 15, -12], [21, 16]]
- B[[3, 0, 9], [8, 15, 0], [21, 16]]
- C[[3, 0, 9], [4, 15, 0], [21, 16]]
- D[[1, 0, 3], [8, 15, 0], [21, 16]]
- Q14MCQ4 Marks·Choose one option
What is the value of _(out2) after executing the code?
- A[3, 9, 8, 15, 21, 16]
- B[9, 8, 15, 21, 16]
- C[8, 15, 21, 16]
- D[3, 0, 9, 8, 15, 0, 21, 16]
End Term · 31 Aug 2025 (FN)End Term
- Q15MCQ3 Marks·Choose one 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)
- A['JA0', 'pa0', 'SC2', 'tah', 'SO4']
- B['JA0', '0p', 'SC2', 'tah', 'SO4']
- C['JA0', '0p', 'SC2', '0t', 'SO4']
- D['JA0', '0p', 'SC2', '0t', '0k']
- Q16MCQ3 Marks·Choose one 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) ?
- A42
- B47
- C39
- D60
- Q17MCQ3 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
- Q18MCQ3 Marks·Choose one 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
- A9
- B8
- C7
- D10
- Q19MCQ3 Marks·Choose one 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)
- A30
- B14
- C16
- D6
- Q20MCQ3 Marks·Choose one 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)
- Aapple_cherry
- Bfig_kiwi
- Cgrape_fig
- Dcherry_apple
- Q21MSQ3 Marks·Choose all 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.
- Anums = [2, 3, 4, 5] squares = list(map(lambda x: x**2, nums))
- Bnums = [4, 9, 16, 25] squares = map(int, nums)
- Cnums = [2, 3, 4, 5] def square(n): return n * n squares = list(map(square, nums))
- Dnums = [2, 3, 4, 5] squares = [] for x in nums: squares.append(x ** 2)
- Enums = [2, 3, 4, 5] squares = list(map(pow, nums, [2]*4))
- Q22MSQ3 Marks·Choose all 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)
- AThe output will contain the string _("Trying division")
- BThe string _("Division by zero") will appear in the output
- CThe division result will be appended to the output
- DThe string _("Cleanup done") will always appear regardless of exceptions
- Q23MSQ3 Marks·Choose all 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?
- AThe list _(original_scores) remains unchanged after calling _(update_scores)
- BThe function _(update_scores) returns a new list
- CThe variable _(score) inside the function is local to the function
- DThe function modifies the _(scores) list in place
- Q24NAT2 Marks·Write the number
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?
Your answer: - Q25NAT2 Marks·Write the number
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?
Your answer: - Q26NAT3 Marks·Write the number
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?
Your answer: - Q27NAT3 Marks·Write the number
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?
Your answer: - Q28NAT3 Marks·Write the number
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?
Your answer: Read the passage below, then answer Q29–Q31
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]
Q29MCQ2 Marks·Choose one optionWhat is the output of filter_and_rank(students) ?
- A['Deep', 'Arya']
- B['Arya', 'Deep']
- C['Deep']
- D['Arya']
- Q30MSQ2 Marks·Choose all correct options
Which of the following students failed to be included due to failing at least one subject?
- ABilal
- BChitra
- CEsha
- DArya
- Q31NAT1 Mark·Write the number
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) ?
Your answer: Read the passage below, then answer Q32–Q34
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)
Q32NAT2 Marks·Write the numberWhat will the output of the given code?
Your answer:- Q33MSQ2 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
- Q34MCQ1 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
- Q35MCQ3 Marks·Choose one option
Given the following code snippet, what will be the output? if None: print("None is True") elif 0: print("0 is True") elif "": print("Empty string is True") else: print("All False")
- ANone is True
- B0 is True
- CEmpty string is True
- DAll False
- Q36MCQ3 Marks·Choose one option
Consider the below code snippet. def updated_val(d, key, val): if key in d: d[key] += val else: d[key] = val return d[key] my_dict = {'a': 2, 'b': 3} print( updated_val(my_dict, 'c', 4) + updated_val(my_dict, 'c', 2) + updated_val(my_dict, 'a', 2) ) What will be the output of the above code
- A6
- B14
- C10
- DRaises KeyError
- Q37MCQ3 Marks·Choose one option
Given the following code snippet, what will be the output? a = (1, 2) b = (3, 4) c = ((5, 6),) d = a + b + c e = d[2:] f = d[:2] + (e[2],) print(f)
- A(3, 4, (5, 6))
- B(3, 4, 5, 6)
- C(1, 2, (5, 6))
- D(1, 2, 5, 6)
- Q38MCQ3 Marks·Choose one option
Consider the below output. 1 4 7 2 5 8 3 6 9 Select the code snippet that will generate the above output.
- Amatrix = [[i + (j+1)*3 for i in range(3)] for j in range(3)] for row in matrix: print(*row)
- Bmatrix = [[(i+1) + j*3 for i in range(3)] for j in range(3)] for row in matrix: print(*row)
- Cmatrix = [[(j+1) + i*3 for j in range(3)] for i in range(3)] for row in matrix: print(*row)
- Dmatrix = [[(i+1) + j*3 for j in range(3)] for i in range(3)] for row in matrix: print(*row)
- Q39MCQ3 Marks·Choose one option
Given the following code snippet, what will be the output? def update_records(records, updates): for key, value in updates.items(): if key in records and isinstance(records[key], dict): for sub_key, sub_val in value.items(): if sub_key in records[key]: records[key][sub_key] += sub_val else: records[key][sub_key] = sub_val else: records[key] = value return records data = { "A": {"x": 10, "y": 20}, "B": {"x": 5, "z": 15}, "C": 100 } updates = { "A": {"x": 5, "z": 5}, "B": {"y": 10}, "C": {"x": 10}, "D": {"w": 7} } result = update_records(data, updates) print(result)
- AA: {'x': 15, 'y': 20, 'z': 5} B: {'x': 5, 'z': 15, 'y': 10} C: {'x': 10} D: {'w': 7}
- BA: {'x': 15, 'y': 20, 'z': 5} B: {'x': 5, 'z': 15, 'y': 10} C: {'x': 110} D: {'w': 7}
- CA: {'x': 5, 'z': 5} B: {'y': 10} C: {'x': 10} D: {'w': 7}
- DA: {'x': 5, 'y': 20, 'z': 5} B: {'x': 5, 'z': 15, 'y': 10} C: 100 D: {'w': 7}
- Q40MCQ3 Marks·Choose one option
Given the following code snippet, what will be the output? def get_square(items, i): return items[i]**2 def safe_get_square(items,i): try: return get_square(items,i) except IndexError: return 0 except: return -1 nums = [5, -2, 3] print(safe_get_square(nums , 1)) print(safe_get_square(nums , -1)) print(safe_get_square([] , -1)) print(safe_get_square(None , 1))
- A25 0 -1 -1
- B4 4 -1 -1
- C4 9 -1 -1
- D4 9 0 -1
- Q41MSQ3 Marks·Choose all correct options
Consider the following snippet of code: t1 = (1, 2, 3) t2 = (4, 5, 6) t3 = t1 + t2 t4 = (t1, t2) print(t3[2:5]) print(len(t4)) print(5 in t2) try: t1[0] = 10 except: t1 = t3[0] print(t1) Select all that apply.
- AThe First Line of output is _((3, 4, 5, 6))
- BThe First Line of output is _((3, 4, 5))
- CThe Second Line of output is _2
- DThe Third Line of output is _(True)
- EThe Fourth Line of output is _3
- Q42MSQ3 Marks·Choose all correct options
Consider the following snippet of code: filename = "test.txt" with open(filename, "w") as f: f.write("\n".join((f"Line{i}" for i in range(1,11)))) with open(filename, "r") as f: f.readline() f.readline() print(f.read(5)) f.readline() print(f.read(10)) f.seek(0) print(f.read(5)) f.readline() f.readline() print(f.read(5)) Select all that apply. Note • If a value is passed to _(f.read) , it reads that many number of characters from the current position of the file pointer. • The _(f.seek) method moves the position of the file pointer to the given number of chars after the start of the file.
- AThe first line of the output is _(Line3) .
- BThe second line of the output is _(Line5) .
- CThe second line of the output is _(Line4) .
- DThere are 5 lines in the output.
- EThe output contains empty lines.
- Q43MCQ3 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
- Q44NAT3 Marks·Write the number
Consider the below python code. lst = [] for i in range(5): lst.append(i) lst.append(i*10) lst[1:4] = [100] print(sum(lst)) What will be the output of the given code?
Your answer: - Q45NAT3 Marks·Write the number
Consider the below python code. def process_array(arr): total = 0 for i, row in enumerate(arr): total += row[i] return total array = [] for i in range(5): row = [] for j in range(i + 1): row.append((i + 1) * (j + 1)) array.append(row) print(process_array(array)) What will be the output of the given code?
Your answer: - Q46NAT3 Marks·Write the number
Consider the below python code. def procedure(child_dict, i): if i not in child_dict.keys(): return 1 ans = 1 for j in child_dict[i]: ans += procedure(child_dict, j) return ans child_dict = dict() child_dict[0] = [1,2] child_dict[1] = [3,4,5] child_dict[2] = [6,7,8] print(procedure(child_dict,0)) What will be the output of the given code?
Your answer: - Q47NAT3 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: Read the passage below, then answer Q48–Q49
Consider the below python code.
def create_and_write_file(filename, num_lines):
with open(filename, "w") as f:
for i in range(1, num_lines + 1):
f.write(f"Line {i}\n")
def random_access_read(filename, seek_pos):
with open(filename, "r") as f:
first_chars = f.read(5)
f.seek(seek_pos)
line = f.readline()
rest = f.readlines()
for line in rest:
print(line.strip())
def overwrite_some_text(filename, overwrite_pos, text):
with open(filename, "r+") as f:
f.seek(overwrite_pos)
original = f.readline()
f.seek(overwrite_pos)
f.write(text + "\n")
filename = "example_file.txt"
num_lines = 6
seek_pos = 10
overwrite_pos = 21
overwrite_text = "OVERWRITTEN_TEXT"
create_and_write_file(filename, num_lines)
overwrite_some_text(filename, overwrite_pos, overwrite_text)
Based on the given code snippet answer the given subquestions.
Q48NAT2 Marks·Write the numberOn executing the given code, how many number of lines will be there in the file example_file.txt ?
Your answer:- Q49MCQ3 Marks·Choose one option
What will be printed if we call random_access_read(filename, seek_pos) immediately after running the given code?
- ALine 1 Line 2 Line 3 OVERWRITTEN_TEXT e 6
- BLine 3 OVERWRITTEN_TEXT e 6
- CLine 3 LinOVERWRITTEN_TEXT
- DLine 1 Line 2 Line 3 Line 4 Line 5 Line 6
Read the passage below, then answer Q50–Q52
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.
Q50MCQ2 Marks·Choose one optionWhat will be the value of the following expression after running the given code snippet? sorted(result["cat_1"] & result["cat_3"])
- A[10]
- B[5]
- C[2, 4, 5, 6, 8, 10]
- D[5, 10]
- Q51NAT2 Marks·Write the number
What will be the value of the following expression after running the given code snippet? len(result["cat_1"] | result["cat_2"] | result["cat_3"])
Your answer: - Q52MSQ2 Marks·Choose all correct options
If result = categorize_numbers([1, 2, 10, 15, 20]) , which of the following expression(s) would be evaluated as _(True) ?
- Aresult == { 'cat_1': {2, 10, 20}, 'cat_2': {1, 15}, 'cat_3': {10, 20, 15} }
- Blen(result["cat_1"] & result["cat_3"]) == 2
- Clen(result["cat_1"] & result["cat_2"]) == 5
- D(result["cat_1"] & result["cat_2"] | result["cat_3"]) == {10,20,15}
End Term · 13 Apr 2025 (FN)End Term
- Q53MCQ3 Marks·Choose one option

- AIt reverses the entire sub-list from left to right, regardless of whether the elements are odd or even.
- BIt reverses only the odd elements in the range [left, right], leaving even elements in their original positions.
- CIt moves all even elements to the left and all odd elements to the right (a partition), but does not change the relative order of the odd elements themselves.
- DIt sorts the sub-list from left to right in ascending order, ignoring whether elements are odd or even.
- Q54MCQ3 Marks·Choose one option

- A2
- B3
- C5
- DIt will give an error
- Q55MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
- Q56MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
- Q57MCQ3 Marks·Choose one option

- AOnly X
- BOnly Y
- COnly Z
- DX and Z
- Q58MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
- Q59NAT3 Marks·Write the number
Your answer: - Q60NAT3 Marks·Write the number
Your answer: - Q61NAT3 Marks·Write the number
Your answer: - Q62NAT3 Marks·Write the number
Your answer: - Q63NAT4 Marks·Write the number
Your answer: - Q64MSQ3 Marks·Choose all correct options

- A"debitcard", "badcredit"
- B"admirer", "married"
- C"schoolmaster", "theclassroom"
- D"aabbcc", "abcabc"
- Q65MSQ3 Marks·Choose all correct options

- A

- B

- C

- D

- A
- Q66MSQ3 Marks·Choose all correct options

- A

- B

- C

- D

- A
Read the passage below, then answer Q67–Q68

Based on the above data, answer the given subquestions.
Q67MCQ1.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
- Q68NAT1.5 Marks·Write the number
If the below main code is executed after the class definition, what will be the output?
Your answer: Read the passage below, then answer Q69–Q71
Q69MCQ1.5 Marks·Choose one option
- A

- B

- C

- D

- A
- Q70MSQ1.5 Marks·Choose all correct options

- A

- B

- C

- D

- A
- Q71MSQ1 Mark·Choose all correct options

- A

- B

- C

- D

- A
End Term · 13 Apr 2025 (AN)End Term
- Q72MCQ3 Marks·Choose one option

- AIt converts all vowels to uppercase and consonants to lowercase while leaving digits unchanged.
- BIt reverses the order of characters in the string while converting all letters to lowercase.
- CIt removes all non-alphabetic characters and alternates uppercase and lowercase letters in the remaining string.
- DIt alternates the case of alphabetical characters based on their position, starting with uppercase at index 0, leaving non-alphabetic characters unchanged.
- Q73MCQ3 Marks·Choose one option

- A2
- B3
- C4
- D6
- Q74MCQ3 Marks·Choose one option

- A

- B

- C

- D

- A
- Q75MCQ3 Marks·Choose one option

- A8
- B4
- C12
- D3
- Q76MCQ3 Marks·Choose one option

- AOnly A
- BOnly B
- COnly C
- DA and C
- Q77MCQ3 Marks·Choose one option

- AOnly Snippet-1 is correct
- BOnly Snippet-2 is correct
- CBoth Snippet-1 and Snippet-2 are correct
- DBoth Snippet-1 and Snippet-2 are incorrect
- Q78NAT3 Marks·Write the number
Your answer: - Q79NAT3 Marks·Write the number
Your answer: - Q80NAT3 Marks·Write the number
Your answer: - Q81NAT3 Marks·Write the number
Your answer: - Q82NAT4 Marks·Write the number
Your answer: - Q83MSQ3 Marks·Choose all correct options

- A"taco cat"
- B"civic room"
- C"racecar"
- D"level up"
- Q84MSQ3 Marks·Choose all correct options

- A

- B

- C

- D

- A
- Q85MSQ3 Marks·Choose all correct options

- A

- B

- C

- D

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

- B

- C

- D

- A
- Q87MCQ1.5 Marks·Choose one option

- A1
- B2
- C3
- DCannot be determined
Read the passage below, then answer Q88–Q90
Based on the below code answer the given subquestions.
Q88NAT1 Mark·Write the number
Your answer:- Q89NAT1.5 Marks·Write the number
Your answer: - Q90NAT1.5 Marks·Write the number
What will be the value passed to the function in the call before the base case, if the function is called with the input 32456 ?
Your answer:
Official KeyMaster Answer Key & Explanations
Official answer keys from IIT Madras BS past papers. Click any question to review.
Reveal KeyCollapse Key
Master Answer Key & Explanations
Official answer keys from IIT Madras BS past papers. Click any question to review.