Test Index
CBSE Class 12 Computer Science 2025 Paper Compartment
© examsnet.com
Question : 31 of 37
Marks:
+1,
-0
(a) Write the output on execution of the following Python code :
P=[3,5,7,4]P.insert(2,3)P.extend([10, 6])print(P)print(P.index(7))print(P[::2])OR(b) Write the output on execution of the following Python code :
def ALTER(Y=25): global X Y += X X += Y print(X,Y,sep="#")X=5; Y=15ALTER(Y)ALTER()print(X,Y,sep="@")
Solution:
(a)Explanation:
P.insert(2,3) puts 3 at index 2: [3, 5, 3, 7, 4]P.extend([10, 6]) adds 10 and 6 at the end: [3, 5, 3, 7, 4, 10, 6]P.index(7) gives the first position of 7, which is 3 (indices start at 0).P[::2] takes every second element from index 0 (indices 0, 2, 4, 6): [3, 3, 4, 6]Output:[3, 5, 3, 7, 4, 10, 6]3[3, 3, 4, 6]OR (b)Explanation:
X is global, so changes to it inside ALTER stay; Y inside the function is a local parameter, so the global Y never changes.Call ALTER(Y): local Y = 15; Y = 15 + 5 = 20; X = 5 + 20 = 25; prints 25#20Call ALTER(): local Y = 25 (default); Y = 25 + 25 = 50; X = 25 + 50 = 75; prints 75#50Last line: global X = 75, global Y = 15 (unchanged); prints 75@15Output:25#2075#5075@15
© examsnet.com
Go to Question: