**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.
**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`.
Which of the following statements is TRUE regarding the code below?
6406537020638.
and
both become
6406537020639.
changes the original list
6406537020640.
becomes
while
becomes
6406537020641.
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.
**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.
Character
Action
`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.
**Answer: the first and second expressions are true.**
For `s = "PyThOn2026"`, string comparisons are case-sensitive and slicing excludes the ending index.
Expression
Value obtained
Boolean 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.
**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.
Object
Type
Can its contents be changed?
`data`
Tuple
No
`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.
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.
**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`.
Index
Input
Rule
Output
0
`"go"`
Uppercase, then reverse
`"OG"`
1
4
Odd index: add 5
9
2
`"cat"`
Uppercase, then reverse
`"TAC"`
3
3
Odd index: add 5
8
4
2
Even index: multiply by 2
4
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.
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:
is replaced with
For the given input
which of the following statements will become TRUE?
6406537020658.
The final output becomes:
6406537020659.
becomes
6406537020660.
integer
becomes
6406537020661.
integer
becomes
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.
Input
Modified rule
Output
`"go"`
Uppercase and reverse
`"OG"`
4
Even value: double
8
`"cat"`
Uppercase and reverse
`"TAC"`
3
Odd value: add 5
8
2
Even value: double
4
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.
**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.
Word
Length
Branch used
Added
`pen`
3
Length less than 5
3
`scale`
5
Contains `a`
2
`book`
4
Length less than 5
4
`eraser`
6
Contains `a`
2
`ink`
3
Length less than 5
3
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`.
Based on the above data, answer the given subquestions.
How many times is the condition
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**.