MauryaHub PYQ Practice

Programming in Python · Quiz 1 · Jan 2026

Programming in Python · Quiz 1 · Jan 2026

← Course papers · Start practice / exam

Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.

14 / 14 published solutions

Question 2 MCQ · 3.0 marks

Consider the following code:
Source diagram or notation
What will be the output?
6406536343723.Source diagram or notation
6406536343724.Source diagram or notation
6406536343725.Source diagram or notation
6406536343726.Source diagram or notation

Published solution

Trace the recursion from its base case. calc(3,0) returns (3,0,1). The next level uses x=3,y=0,z=1 and returns (4,3,2). The final level uses x=4,y=3,z=2 and returns (5,7,4). Unpacking gives p=5,q=7,r=4, so print(q,r) outputs `7 4`. Each return expression uses the values received from the smaller call. **Answer: B.** A: **Incorrect:** Does not accumulate y across both recursive levels. B: **Correct:** Matches q=7 and r=4 after the two recursive returns. C: **Incorrect:** Incorrectly changes both the accumulation and doubling count. D: **Incorrect:** Does not match the traced q and r values.

Report a correction for Q2

Question 3 MCQ · 3.0 marks

Consider the following code:
Source diagram or notation
What will be the output?
6406536343727.Source diagram or notation
6406536343728.Source diagram or notation
6406536343729.Source diagram or notation
6406536343730.Source diagram or notation

Published solution

The loop processes 'python' from left to right. It appends p, y and t. At h, continue skips the append for that iteration. At o, break exits the entire loop before appending o, so n is never visited. The final string is `pyt`. **Answer: B.** A: **Incorrect:** Includes h despite continue and o despite break. B: **Correct:** Contains only p, y and t, which reach the append. C: **Incorrect:** Treats break as if it only skipped o, and also mishandles h. D: **Incorrect:** n cannot be appended because the loop stops at o.

Report a correction for Q3

Question 4 MCQ · 3.0 marks

Consider the following Python code:
Source diagram or notation
What will be the output?
6406536343735.Source diagram or notation
6406536343736.Source diagram or notation
6406536343737.Source diagram or notation
6406536343738.Source diagram or notation

Published solution

The loop removes the last digit using n%10, then removes that digit using n//10. Its successive (digit,p,contribution) triples are (4,1,4), (3,2,6), and (2,3,6). The total is 4+6+6=16. Position weights increase from the units digit towards the left, rather than applying to digits left-to-right. **Answer: D.** A: **Incorrect:** 20 is not the sum of the three traced contributions. B: **Incorrect:** 14 omits part of the weighted sum. C: **Incorrect:** 24 does not match the digit weights 1,2,3. D: **Correct:** 16 equals 4 times 1 plus 3 times 2 plus 2 times 3.

Report a correction for Q4

Question 5 MCQ · 4.0 marks

Consider the following code:
Source diagram or notation
What will be the output?
6406536343731.Source diagram or notation
6406536343732.Source diagram or notation
6406536343733.Source diagram or notation
6406536343734.Source diagram or notation

Published solution

a.copy() creates a separate list b. Sorting b changes only b to [1,1,3,4,5]. Then a[2]=9 replaces the third element of a, giving [3,1,9,1,5]. Thus the output is `[3, 1, 9, 1, 5] [1, 1, 3, 4, 5]`. A shallow copy suffices because the elements are immutable integers. **Answer: B.** A: **Incorrect:** Leaves a unchanged even though a[2] is assigned 9. B: **Correct:** Correctly keeps the original-order a and separately sorted b. C: **Incorrect:** Treats the two lists as if sorting and replacement were shared. D: **Incorrect:** Treats the copy as an alias and also loses b's sorting.

Report a correction for Q5

Question 6 MSQ · 4.0 marks

Consider the following Python code:
Source diagram or notation
Which of the following statements are true?
6406536343739.
The final value of
Source diagram or notation
is
Source diagram or notation
6406536343740.
The character
Source diagram or notation
increases
Source diagram or notation
by
Source diagram or notation
6406536343741.
The letter
Source diagram or notation
increases the value of
Source diagram or notation
by
Source diagram or notation
and the character
Source diagram or notation
increases
Source diagram or notation
by
Source diagram or notation
6406536343742.
The letter
Source diagram or notation
increases the value of
Source diagram or notation
by
Source diagram or notation
and the character
Source diagram or notation
increases
Source diagram or notation
by
Source diagram or notation

Published solution

The branches form one if/elif chain, so each character can contribute only once. In 'abracadabra', a occurs five times and contributes 1 each; b occurs twice and contributes 2 each; c occurs once and contributes 3; r and d contribute zero. Total=5+4+3=12. The a characters do not also enter the later membership test in 'abc', because their first branch already succeeded. **Answer: A, B, D.** A: **Correct:** The total is 12. B: **Correct:** a is a vowel and contributes 1 via the first branch. C: **Incorrect:** Although r contributes no increment, the stated alternative does not describe the actual b/c branch increments; b adds 2, not 3. D: **Correct:** b adds 2 and c adds 3 through their respective first matching branches.

Report a correction for Q6

Question 7 MSQ · 4.0 marks

Consider the following Python code:
Source diagram or notation
Which of the following statements are true?
6406536343743.
The output of the first
Source diagram or notation
statement is
Source diagram or notation
6406536343744.
The output of the second
Source diagram or notation
statement is
Source diagram or notation
6406536343745.
The default value of
Source diagram or notation
is used in the second function call
6406536343746.
The function
Source diagram or notation
returns two values as a tuple
6406536343747.
The output of the second
Source diagram or notation
statement is
Source diagram or notation

Published solution

The first call process(5) uses default y=3. Since 5>3, x becomes 5-3=2; then y=2*2=4, returning (2,4). The second call process(2,4) explicitly supplies y=4; since 2>4 is false, x becomes 2+4=6 and y becomes 12. The prints are `2 4` and `6 12`. A comma-separated return expression packages its two items as a tuple for unpacking. **Answer: A, D, E.** A: **Correct:** The first call returns (2,4). B: **Incorrect:** The second call returns (6,12), not (5,10). C: **Incorrect:** The second call passes 4 explicitly, so it does not use the default 3. D: **Correct:** return x,y creates a two-item tuple. E: **Correct:** The second print outputs 6 and 12.

Report a correction for Q7

Question 8 NAT · 4.0 marks

What is the output of the following snippet of code?
Source diagram or notation

Published solution

Evaluate the three terms separately. data[0] is 'Courses', whose length is 7. data[1][1] is '2026', and converting and summing its digits gives 2+0+2+6=10. data[2] is 'quiz', whose length is 4. Therefore the printed total is 7+10+4=21. Indexing into the nested list is different from taking its length. **Answer: 21.**

Report a correction for Q8

Question 9 NAT · 4.0 marks

Consider the following snippet of code. What will the output be?
Source diagram or notation

Published solution

For each word, only the first matching branch runs. pen has length 3 and is appended to small; book has length 4 and does not begin with p, so result gains 3; pencil gains 2; eraser gains 3; ink is appended to small. Thus small=['pen','ink'] has length 2 and result=8. The print is 2+8=10. pen does not also add 2 because it already matched the short-word branch. **Answer: 10.**

Report a correction for Q9

Question 10 NAT · 4.0 marks

What is the output of the following snippet of code? **Note:**
Source diagram or notation
:checks whether an object belongs to a given type or any of its subclasses.
Source diagram or notation

Published solution

Check each independent if statement. a=True is a bool and true, so add 3. b=10 is an int and truthy, so add 4. c=False is a bool and not c is true, so add 5. d=0 is an int, not a bool, so the bool test adds nothing; its int test and not d both succeed, adding 2. Total=3+4+5+2=14. Although bool subclasses int in Python, an ordinary integer zero is not an instance of bool. **Answer: 14.**

Report a correction for Q10

Question 11 NAT · 3.0 marks

What is the output of the following snippet of code?
Source diagram or notation

Published solution

The list comprehension doubles even integers and adds 1 to odd integers. For [1,2,1,3,3,4,5], it produces [2,4,2,4,4,8,6]. Summing gives 2+4+2+4+4+8+6=30. The conditional expression is evaluated separately for every element; it does not filter out odd values. **Answer: 30.**

Report a correction for Q11

Question 12 MCQ · 4.0 marks

Consider the following snippet of code and answer the sub-questions:
Source diagram or notation
What is the value of
Source diagram or notation
after executing the given code?
6406536343752.Source diagram or notation
6406536343753.Source diagram or notation
6406536343754.Source diagram or notation
6406536343755.Source diagram or notation

Published solution

For each pair, test the second component. If it is even, double the first component; otherwise add 1 to the first. (2,3) gives 3; (4,6) gives 8; (5,1) gives 6; (3,8) gives 6. The result is `[3,8,6,6]`. The loop increments i after each append, visiting all four pairs exactly once. **Answer: B.** A: **Incorrect:** Does not apply the stated even/odd rule to the second components. B: **Correct:** Matches all four traced values in order. C: **Incorrect:** Incorrectly transforms the first and third pairs. D: **Incorrect:** The second pair's even second component requires 4 times 2=8, not 6.

Report a correction for Q12

Question 13 MCQ · 3.0 marks

Consider the following snippet of code and answer the sub-questions:
Source diagram or notation
In the given code, if we change the condition to
Source diagram or notation
instead of
Source diagram or notation
, what will be the value of
Source diagram or notation
?
6406536343756.Source diagram or notation
6406536343757.Source diagram or notation
6406536343758.Source diagram or notation
6406536343759.Source diagram or notation

Published solution

Changing the condition to item[1]%2==1 swaps which parity uses the doubling branch. (2,3) now gives 4; (4,6) gives 5; (5,1) gives 10; (3,8) gives 4. Hence output becomes `[4,5,10,4]`. The branches' arithmetic stays unchanged; only the parity test changes. **Answer: A.** A: **Correct:** Matches the four outputs after reversing the parity condition. B: **Incorrect:** This is the original output before the condition changes. C: **Incorrect:** Keeps some original-branch results instead of consistently reversing parity. D: **Incorrect:** Does not consistently apply double-for-odd and plus-one-for-even.

Report a correction for Q13

Question 14 MCQ · 4.0 marks

Consider the following snippet of code and answer the sub-questions:
Source diagram or notation
What are the values of
Source diagram or notation
and
Source diagram or notation
after executing the given code?
6406536343760.Source diagram or notation
6406536343761.Source diagram or notation
6406536343762.Source diagram or notation
6406536343763.Source diagram or notation

Published solution

For text='CoMPuter', indices 1 through 4 give A='oMPu', because slice stop 5 is excluded. The final four characters give B='uter'. Strings compare lexicographically and case-sensitively; at the first character, 'o' is less than 'u', so A>B is false. The else branch returns B,A. Therefore P='uter' and Q='oMPu'. **Answer: B.** A: **Incorrect:** Returns A,B even though the condition is false. B: **Correct:** Correctly returns B,A with the two actual slices. C: **Incorrect:** Uses an incorrect slice and the wrong returned values. D: **Incorrect:** The last slice is correct, but Q should be oMPu, not MPut.

Report a correction for Q14

Question 15 MSQ · 3.0 marks

Consider the following snippet of code and answer the sub-questions:
Source diagram or notation
Which of the following statements are true?
6406536343764.
Both
Source diagram or notation
and
Source diagram or notation
are substrings of
Source diagram or notation
6406536343765.
The expression
Source diagram or notation
evaluates to
Source diagram or notation
6406536343766.
The comparison ignores uppercase and lowercase letters
6406536343767.
The expression
Source diagram or notation
evaluates to
Source diagram or notation

Published solution

Using the function's local values, A='oMPu' and B='uter'. They are slices, hence substrings of text. A[1:] is 'MPu', while B[:-1] is 'ute'; these are unequal. Comparisons are case-sensitive and lexicographic, so text[1:5]>text[-4:] is false because 'o'<'u'. A and B are local to process; a literal attempt to evaluate their names outside the function without defining them would raise NameError. The exercise's comparison statements refer to their values inside the function. **Answer: A, D.** A: **Correct:** Both returned values originate from contiguous slices of text. B: **Incorrect:** MPu and ute are different strings, so the equality is false. C: **Incorrect:** Python string comparison does not ignore case. D: **Correct:** oMPu is lexicographically less than uter, so the displayed greater-than expression is false.

Report a correction for Q15