Test Index
CBSE Class 12 Computer Science 2026 Paper Compartment
© examsnet.com
Question : 31 of 37
Marks:
+1,
-0
(a) Predict the output on execution of the following Python code :
SCORES = [5, 12, 7, 20, 10, 18]for X in range(len(SCORES)): if SCORES[X] % 4 == 0: SCORES[X] = SCORES[X] + SCORES[X-1] elif SCORES[X] % 3 == 0: SCORES[X] = SCORES[len(SCORES) - 1 - X] + 5 else: SCORES[X] = SCORES[X] // 2for Y in range(0, len(SCORES), 2): if Y + 1 < len(SCORES): print(SCORES[Y], SCORES[Y+1], sep="$") else: print(SCORES[Y], sep="$")OR(b) Predict the output on execution of the following Python code :
def Transform(D_A, D_B): D_C = {} D_C.update(D_A) D_A.update(D_B) D_B.update(D_C) return D_CInit_Stock = {"Chocolate": 100, "Cookie": 50}New_Arriv = {"Cookie": 60, "Chocolate": 120}T_Data = Transform(Init_Stock, New_Arriv)print(Init_Stock)print(New_Arriv)print(T_Data)
Solution:
(a)Concept: The first loop changes the list in place, so a later element uses the already changed values of earlier elements. The second loop prints the elements in pairs, joined by
Second loop: Y takes 0, 2, 4. For each Y,
$ (the sep value).First loop (X = 0 to 5):| X | SCORES[X] | Test | New value | SCORES after the step |
| 0 | 5 | not ÷4, not ÷3 | 5 // 2 = 2 | [2, 12, 7, 20, 10, 18] |
| 1 | 12 | 12 % 4 == 0 | 12 + SCORES[0] = 12 + 2 = 14 | [2, 14, 7, 20, 10, 18] |
| 2 | 7 | not ÷4, not ÷3 | 7 // 2 = 3 | [2, 14, 3, 20, 10, 18] |
| 3 | 20 | 20 % 4 == 0 | 20 + SCORES[2] = 20 + 3 = 23 | [2, 14, 3, 23, 10, 18] |
| 4 | 10 | not ÷4, not ÷3 | 10 // 2 = 5 | [2, 14, 3, 23, 5, 18] |
| 5 | 18 | 18 % 4 = 2, 18 % 3 == 0 | SCORES[6-1-5] + 5 = SCORES[0] + 5 = 2 + 5 = 7 | [2, 14, 3, 23, 5, 7] |
Y + 1 < 6 is True, so two values are printed:Y = 0: SCORES[0], SCORES[1] = 2, 14 → 2$14Y = 2: SCORES[2], SCORES[3] = 3, 23 → 3$23Y = 4: SCORES[4], SCORES[5] = 5, 7 → 5$7Output:2$143$235$7Key point: At X = 1 the code adds SCORES[0], which is already 2 (not the original 5). At X = 5, 18 is not divisible by 4 but is divisible by 3, so the
elif branch runs.OR (b)Concept: d1.update(d2) copies every key:value pair of d2 into d1: an existing key keeps its position but gets the new value; a new key is added at the end. Dictionaries are mutable and are passed by reference, so changes made to D_A and D_B inside the function change Init_Stock and New_Arriv themselves.Step by step:1. D_C = {}, then D_C.update(D_A) → D_C = {'Chocolate': 100, 'Cookie': 50} (a separate copy of the old Init_Stock).2. D_A.update(D_B) → Init_Stock gets the new values: {'Chocolate': 120, 'Cookie': 60} (key order Chocolate, Cookie is kept).3. D_B.update(D_C) → New_Arriv gets D_C's values: {'Cookie': 50, 'Chocolate': 100} (its own key order Cookie, Chocolate is kept).4. D_C is returned, so T_Data = {'Chocolate': 100, 'Cookie': 50}.Output:{'Chocolate': 120, 'Cookie': 60}{'Cookie': 50, 'Chocolate': 100}{'Chocolate': 100, 'Cookie': 50}Key point: D_C was filled before D_A changed, so it still holds the original stock (100, 50). That is why the two dictionaries effectively swap their values. Python prints strings in a dictionary with single quotes.© examsnet.com
Go to Question: