MauryaHub PYQ Practice

Programming in Python · Quiz 1 · May 2026

Programming in Python · Quiz 1 · May 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 / 15 published solutions

Question 2 MCQ · 0.0 marks

**NAT → integer** For all NAT questions in this exam, the answer will always be an integer and not a float value.
6406537020624.
Instructions has been mentioned above.
6406537020625.
This Instructions is just for a reference & not for an evaluation.

A published solution is not available for this question yet.

Report a correction for Q2

Question 3 MCQ · 3.0 marks

What is the output of the following code?
Source diagram or notation
6406537020626.Source diagram or notation
6406537020627.Source diagram or notation
6406537020628.Source diagram or notation
6406537020629.Source diagram or notation

Published solution

**Answer: `0009`.** `int("07")` is `7`, while `len("07")` is `2`, so `y = 7 + 2 = 9`. The format specifier `04d` prints an integer in a field of at least four digits, padding on the left with zeros. Therefore `9` is printed as `0009`. A: Correct. Four-digit zero padding changes 9 to `0009`. B: Incorrect. `009` has only three digits; the requested width is four. C: Incorrect. `9` is the numeric value, but this omits the formatting zeros. D: Incorrect. The code formats `y = 9`, not the original value 7.

Report a correction for Q3

Question 4 MCQ · 3.0 marks

What is the output of the following code?
Source diagram or notation
6406537020630.Source diagram or notation
6406537020631.Source diagram or notation
6406537020632.Source diagram or notation
6406537020633.Source diagram or notation

Published solution

**Answer: `[2, 8, 6] [2, 4, 6, 6]`.** `M = L` makes `M` and `L` refer to the same list. `N = L[:]` creates a separate list.
Statement`L` (also `M`)`N`
Initial values`[2, 4, 6]``[2, 4, 6]`
`M[1] = M[0] + N[-1]``[2, 8, 6]``[2, 4, 6]`
`N.append(M[1] - L[0])``[2, 8, 6]``[2, 4, 6, 6]`
The appended value is `8 - 2 = 6`. `print(L, N)` displays the two lists separated by a space. A: Correct. Updating `M[1]` also updates `L[1]`, and 6 is appended only to `N`. B: Incorrect. The appended value is `M[1] - L[0] = 8 - 2 = 6`, not 8. C: Incorrect. `M` aliases `L`, so `L[1]` changes from 4 to 8. D: Incorrect. `append` is called on the separate list `N`, not on `L`.

Report a correction for Q4

Question 5 MCQ · 3.0 marks

Which of the following statements is TRUE regarding the code below?
Source diagram or notation
6406537020638.Source diagram or notation
and
Source diagram or notation
both become
Source diagram or notation
6406537020639.Source diagram or notation
changes the original list
6406537020640.Source diagram or notation
becomes
Source diagram or notation
while
Source diagram or notation
becomes
Source diagram or notation
6406537020641.Source diagram or notation
returns a new sorted list

Published solution

**Answer: `B = [1, 4, 5]` and `A = [5, 4, 1]`.** `sorted(A)` creates a new list in ascending order, which is assigned to `B`. It does not change `A`. Then `A.sort(reverse=True)` sorts `A` itself in descending order. Because `B` is a separate list, it stays `[1, 4, 5]`. A: Incorrect. `B` remains ascending; sorting `A` later does not change `B`. B: Incorrect. `sorted(A)` returns a new list and leaves the original list unchanged. C: Correct. `B` is the ascending copy, and `A` is sorted in place in descending order. D: Incorrect. `list.sort()` modifies the existing list and returns `None`; it does not return a new sorted list.

Report a correction for Q5

Question 6 MCQ · 4.0 marks

Consider the following code.
Source diagram or notation
What will be printed?
6406537020634.Source diagram or notation
6406537020635.Source diagram or notation
6406537020636.Source diagram or notation
6406537020637.Source diagram or notation

Published solution

**Answer: `DC`.** A vowel causes `continue`, so that character is skipped. The letter `t` causes `break`, which ends the loop before `t` can be appended.
CharacterAction`result`
`e`Skip vowel`""`
`d`Append uppercase`"D"`
`u`Skip vowel`"D"`
`c`Append uppercase`"DC"`
`a`Skip vowel`"DC"`
`t`End loop`"DC"`
The remaining characters are never processed. A: Correct. Only `d` and `c` are appended before the loop stops. B: Incorrect. `break` runs before the append statement for `t`, so `T` is not added. C: Incorrect. The loop stops at `t`, so it never reaches `n`. D: Incorrect. The initial `e` is a vowel and is skipped.

Report a correction for Q6

Question 7 MSQ · 4.0 marks

Consider the following code.
Source diagram or notation
Select all expressions that evaluate to
Source diagram or notation
.
6406537020642.Source diagram or notation
6406537020643.Source diagram or notation
6406537020644.Source diagram or notation
6406537020645.Source diagram or notation

Published solution

**Answer: the first and second expressions are true.** For `s = "PyThOn2026"`, string comparisons are case-sensitive and slicing excludes the ending index.
ExpressionValue obtainedBoolean result
`"Th" in s`The substring `Th` occurs at indices 2 and 3`True`
`s.lower() == "python2026"`Lowercase string is `"python2026"``True`
`s[2:6] == "Thon"`Slice is `"ThOn"``False`
`s[::-1][0] == "p"`First character of reversed string is `"6"``False`
A: Correct. `Th` occurs exactly, with the same case, in `PyThOn2026`. B: Correct. `.lower()` produces `python2026`. C: Incorrect. `s[2:6]` is `ThOn`, with uppercase O; it is not `Thon`. D: Incorrect. Reversing the string puts its final character, `6`, at index 0.

Report a correction for Q7

Question 8 MSQ · 4.0 marks

Consider the following Python code.
Source diagram or notation
Which of the following statements will run without giving an error?
6406537020646.Source diagram or notation
6406537020647.Source diagram or notation
6406537020648.Source diagram or notation
6406537020649.Source diagram or notation

Published solution

**Answer: the first, second and fourth statements run without error.** The outer tuple cannot have its elements reassigned, but mutable objects stored inside it can still be changed.
ObjectTypeCan its contents be changed?
`data`TupleNo
`data[0]`Set `{1, 2}`Yes
`data[1]`List `[3, 4]`Yes
`data[2]`Tuple `(5, 6)`No
Thus the set can receive 7, the list can be edited or appended to, but assigning to an element of the inner tuple raises `TypeError`. A: Correct. `data[0]` is a mutable set, so `.add(7)` is valid. B: Correct. `data[1]` is a mutable list, so changing its first item to 10 is valid. C: Incorrect. `data[2]` is a tuple, so `data[2][1] = 9` raises `TypeError`. D: Correct. `data[2][0]` reads 5, and appending it to the mutable list `data[1]` is valid.

Report a correction for Q8

Question 9 NAT · 4.0 marks

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

Published solution

**Answer: 28.** The list comprehension adds 1 to each even number and doubles each odd number.
`x`BranchNew value
3Odd: `x * 2`6
5Odd: `x * 2`10
2Even: `x + 1`3
8Even: `x + 1`9
So `new = [6, 10, 3, 9]`, and `sum(new) = 6 + 10 + 3 + 9 = 28`.

Report a correction for Q9

Question 10 NAT · 4.0 marks

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

Published solution

**Answer: 0.**
VariableEvaluationValue
`A`Two occurrences of `m` in `"python programming"`2
`B``text.split()` gives `["python", "programming"]`2
`C``len('text')` counts the literal four-character string4
Therefore `A + B - C = 2 + 2 - 4 = 0`. The quotes in `len('text')` matter: it does not take the length of the variable `text`.

Report a correction for Q10

Question 11 NAT · 4.0 marks

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

Published solution

**Answer: 9.** `num % 10` extracts the last digit, and `num //= 10` removes it. Only odd digits are added.
`num` before iterationLast digitAdded?`total`
5311Yes1
533Yes4
55Yes9
After removing 5, `num` becomes 0 and the loop stops. The printed value is `9`.

Report a correction for Q11

Question 12 NAT · 3.0 marks

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

Published solution

**Answer: 7.** For each `i`, the inner loop starts at `j = 0`. If `j == 2`, `break` exits the inner loop before `count += 1` runs.
`i`Values of `j` that increase `count`Increase
101
20, 12
30, 12
40, 12
Only the inner loop ends at a `break`; the outer loop continues. Final count is `1 + 2 + 2 + 2 = 7`.

Report a correction for Q12

Question 13 MCQ · 4.0 marks

Source diagram or notation
Note: isinstance(val, datatype) returns True if val is of object of type 'datatype' and False, otherwise. Based on the above data, answer the given subquestions.
What is the value of
Source diagram or notation
?
6406537020654.Source diagram or notation
6406537020655.Source diagram or notation
6406537020656.Source diagram or notation
6406537020657.Source diagram or notation

Published solution

**Answer: `['OG', 9, 'TAC', 8, 4]`.** `enumerate(items)` starts at index 0. Strings are uppercased and reversed. For integers, the code checks the parity of the index `i`.
IndexInputRuleOutput
0`"go"`Uppercase, then reverse`"OG"`
14Odd index: add 59
2`"cat"`Uppercase, then reverse`"TAC"`
33Odd index: add 58
42Even index: multiply by 24
Appending these values in order gives the first option. A: Correct. This follows both the string transformation and the zero-based index rule for integers. B: Incorrect. Strings must be reversed after uppercasing, and the integer at index 3 becomes 8. C: Incorrect. Integers use index parity: index 1 gives 9, index 3 gives 8, and index 4 gives 4. D: Incorrect. `go` must become `OG`; the final integer 2 is at even index 4 and becomes 4.

Report a correction for Q13

Question 14 MSQ · 3.0 marks

Source diagram or notation
Note: isinstance(val, datatype) returns True if val is of object of type 'datatype' and False, otherwise. Based on the above data, answer the given subquestions.
Suppose the following condition inside the transform() function:
Source diagram or notation
is replaced with
Source diagram or notation
For the given input
Source diagram or notation
which of the following statements will become TRUE?
6406537020658.
The final output becomes:
Source diagram or notation
6406537020659.Source diagram or notation
becomes
Source diagram or notation
6406537020660.
integer
Source diagram or notation
becomes
Source diagram or notation
6406537020661.
integer
Source diagram or notation
becomes
Source diagram or notation

Published solution

**Answer: the first and third statements are true.** Replacing `i % 2 == 0` with `val % 2 == 0` makes the integer branch depend on the value rather than its position. The string branch remains unchanged.
InputModified ruleOutput
`"go"`Uppercase and reverse`"OG"`
4Even value: double8
`"cat"`Uppercase and reverse`"TAC"`
3Odd value: add 58
2Even value: double4
The result is `['OG', 8, 'TAC', 8, 4]`. A: Correct. The complete result is `['OG', 8, 'TAC', 8, 4]`. B: Incorrect. The string branch still uppercases and reverses, so `go` becomes `OG`, not `GO`. C: Correct. The integer 3 is odd, so it becomes `3 + 5 = 8`. D: Incorrect. The integer 4 is even, so it becomes `4 * 2 = 8`, not 9.

Report a correction for Q14

Question 15 MCQ · 4.0 marks

Source diagram or notation
Based on the above data, answer the given subquestions.
What is the value of
Source diagram or notation
?
6406537020662.Source diagram or notation
6406537020663.Source diagram or notation
6406537020664.Source diagram or notation
6406537020665.Source diagram or notation

Published solution

**Answer: 14.** A word shorter than 5 adds its length. Otherwise, a word containing `a` adds 2; all other words add 1. Only one branch runs for each word.
WordLengthBranch usedAdded
`pen`3Length less than 53
`scale`5Contains `a`2
`book`4Length less than 54
`eraser`6Contains `a`2
`ink`3Length less than 53
Therefore `ans = 3 + 2 + 4 + 2 + 3 = 14`. A length of exactly 5 does not satisfy `< 5`. A: Incorrect. Adding the five branch contributions gives 14, not 13. B: Incorrect. The contributions are 3, 2, 4, 2 and 3, totaling 14. C: Incorrect. The function returns 14 after all five words are processed. D: Correct. `3 + 2 + 4 + 2 + 3 = 14`.

Report a correction for Q15

Question 16 NAT · 3.0 marks

Source diagram or notation
Based on the above data, answer the given subquestions.
How many times is the condition
Source diagram or notation
evaluated?

Published solution

**Answer: 5.** The loop visits all five words: `pen`, `scale`, `book`, `eraser` and `ink`. At the start of each iteration it evaluates `len(word) < 5` once. The condition is true for three words and false for two, but both true and false checks count as evaluations. Hence it is evaluated **5 times**.

Report a correction for Q16