Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Tuples & sets
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
Q1MSQ4 Marks·Choose all correct optionsConsider 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
- Q2NAT3 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 Q3–Q4
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)
Q3MCQ4 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]
- Q4NAT4 Marks·Write the number
How many times is the inner _(for x in item:) loop executed in total when running analyze(sample) ?
Your answer:
End Term · 31 Aug 2025 (FN)End Term
- Q5NAT3 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:
End Term · 31 Aug 2025 (AN)End Term
- Q6MCQ3 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)
- Q7MSQ3 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
Read the passage below, then answer Q8–Q10
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.
Q8MCQ2 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]
- Q9NAT2 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: - Q10MSQ2 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
- Q11MCQ3 Marks·Choose one option

- AOnly X
- BOnly Y
- COnly Z
- DX and Z
End Term · 13 Apr 2025 (AN)End Term
- Q12MCQ3 Marks·Choose one option

- AOnly A
- BOnly B
- COnly C
- DA and C
- Q13NAT3 Marks·Write the number
Your answer:
End Term · 22 Dec 2024 (AN)End Term
- Q14MSQ3 Marks·Choose all correct options

- A

- B

- C

- D

- A