100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 120
During a review of range with positive step, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
print(list(range(0,8,2)))
Program B:
print(sum(range(2,11,4)))
Program C:
print(list(range(3,3,2)))
- Program B prints '18'.
- Program B prints '10'.
- Program C prints '[]'.
- Program A prints "['aa', 'bb']".
- Program C prints '18'.
Explanation
Correct Answers
A:Running Program B prints '18'. The third range argument controls the step, and the stop endpoint remains excluded.
C:Running Program C prints '[]'. The third range argument controls the step, and the stop endpoint remains excluded.
Incorrect Answers
B:Program B does not produce '10'; its verified result is: Prints '18'. The third range argument controls the step, and the stop endpoint remains excluded.
D:Program A does not produce "['aa', 'bb']"; its verified result is: Prints '[0, 2, 4, 6]'. The third range argument controls the step, and the stop endpoint remains excluded.
E:Program C does not produce '18'; its verified result is: Prints '[]'. The third range argument controls the step, and the stop endpoint remains excluded.
Question 121
A learner is checking range descending with negative step. What is the exact printed result or uncaught exception?print(list(range(5,0,-2)))
- Prints '[5, 3, 1]'
- Prints '[1, 3, 5]'
- Prints '[5, 3]'
- Prints '[3, 1]'
Explanation
Correct Answer
A:The snippet prints '[5, 3, 1]'. A negative range step decreases values and still excludes the stop bound.
Incorrect Answers
B:This predicts that the snippet prints '[1, 3, 5]', but executing the displayed Python 3 code prints '[5, 3, 1]'. A negative range step decreases values and still excludes the stop bound.
C:This predicts that the snippet prints '[5, 3]', but executing the displayed Python 3 code prints '[5, 3, 1]'. A negative range step decreases values and still excludes the stop bound.
D:This predicts that the snippet prints '[3, 1]', but executing the displayed Python 3 code prints '[5, 3, 1]'. A negative range step decreases values and still excludes the stop bound.
Question 122
A developer tests range descending with negative step. The following code prints '[4, 3, 2, 1, 0]'. Which explanation best accounts for that observed behavior?print(list(range(4,-1,-1)))
- An else block belongs to its indentation-level if; nested else is not automatically the outer else.
- A negative range step decreases values and still excludes the stop bound.
- A loop can use membership tests to include or exclude selected values from an accumulator.
- pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '[4, 3, 2, 1, 0]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The which else belongs to if topic does not explain why the code prints '[4, 3, 2, 1, 0]'. The relevant Python rule is: A negative range step decreases values and still excludes the stop bound.
C:The loop filtering with membership topic does not explain why the code prints '[4, 3, 2, 1, 0]'. The relevant Python rule is: A negative range step decreases values and still excludes the stop bound.
D:The pass as a no-op placeholder topic does not explain why the code prints '[4, 3, 2, 1, 0]'. The relevant Python rule is: A negative range step decreases values and still excludes the stop bound.
Question 123
A learner is checking range descending with negative step. After this modification, what does Python 3 actually do?print(len(range(10,3,-3)))
- Prints '4'
- Prints '5'
- Prints '2'
- Prints '3'
Explanation
Correct Answer
D:The snippet prints '3'. A negative range step decreases values and still excludes the stop bound.
Incorrect Answers
A:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '3'. A negative range step decreases values and still excludes the stop bound.
B:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '3'. A negative range step decreases values and still excludes the stop bound.
C:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints '3'. A negative range step decreases values and still excludes the stop bound.
Question 124
During a review of range descending with negative step, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
print(list(range(4,-1,-1)))
Program B:
print(len(range(10,3,-3)))
Program C:
print(list(range(2,6,-1)))
- Program B prints '3'.
- Program A raises zerodivisionerror.
- Program B prints '1'.
- Program C prints 'no'.
- Program C prints '[]'.
Explanation
Correct Answers
A:Running Program B prints '3'. A negative range step decreases values and still excludes the stop bound.
E:Running Program C prints '[]'. A negative range step decreases values and still excludes the stop bound.
Incorrect Answers
B:Program A does not raises zerodivisionerror; its verified result is: Prints '[4, 3, 2, 1, 0]'. A negative range step decreases values and still excludes the stop bound.
C:Program B does not produce '1'; its verified result is: Prints '3'. A negative range step decreases values and still excludes the stop bound.
D:Program C does not produce 'no'; its verified result is: Prints '[]'. A negative range step decreases values and still excludes the stop bound.
Question 125
A learner is checking for loop accumulating a sum. What is the exact printed result or uncaught exception?total=0
for n in [2,3,5]: total+=n
print(total)
- Prints '11'
- Prints '12'
- Prints '9'
- Prints '10'
Explanation
Correct Answer
D:The snippet prints '10'. A for loop visits each iterable element and can update a running accumulator on each pass.
Incorrect Answers
A:This predicts that the snippet prints '11', but executing the displayed Python 3 code prints '10'. A for loop visits each iterable element and can update a running accumulator on each pass.
B:This predicts that the snippet prints '12', but executing the displayed Python 3 code prints '10'. A for loop visits each iterable element and can update a running accumulator on each pass.
C:This predicts that the snippet prints '9', but executing the displayed Python 3 code prints '10'. A for loop visits each iterable element and can update a running accumulator on each pass.
Question 126
A developer tests for loop accumulating a sum. The following code prints '6'. Which explanation best accounts for that observed behavior?s=1
for x in range(1,4): s*=x
print(s)
- A for loop else clause does not run when a break ends the loop early.
- A for loop visits each iterable element and can update a running accumulator on each pass.
- Every outer iteration starts a full inner loop unless control flow explicitly interrupts it.
- The not operator inverts truthiness; it does not numerically negate an operand.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '6'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The for else suppressed by break topic does not explain why the code prints '6'. The relevant Python rule is: A for loop visits each iterable element and can update a running accumulator on each pass.
C:The nested for loops count Cartesian pairs topic does not explain why the code prints '6'. The relevant Python rule is: A for loop visits each iterable element and can update a running accumulator on each pass.
D:The not reverses Boolean conditions topic does not explain why the code prints '6'. The relevant Python rule is: A for loop visits each iterable element and can update a running accumulator on each pass.
Question 127
A learner is checking for loop accumulating a sum. After this modification, what does Python 3 actually do?v=0
for x in (1,4,2): v=v*10+x
print(v)
- Prints '142'
- Prints '143'
- Prints '141'
- Prints '144'
Explanation
Correct Answer
A:The snippet prints '142'. A for loop visits each iterable element and can update a running accumulator on each pass.
Incorrect Answers
B:This predicts that the snippet prints '143', but executing the displayed Python 3 code prints '142'. A for loop visits each iterable element and can update a running accumulator on each pass.
C:This predicts that the snippet prints '141', but executing the displayed Python 3 code prints '142'. A for loop visits each iterable element and can update a running accumulator on each pass.
D:This predicts that the snippet prints '144', but executing the displayed Python 3 code prints '142'. A for loop visits each iterable element and can update a running accumulator on each pass.
Question 128
During a review of for loop accumulating a sum, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
s=1
for x in range(1,4): s*=x
print(s)
Program B:
v=0
for x in (1,4,2): v=v*10+x
print(v)
Program C:
s=0
for i in range(3): s+=i*i
print(s)
- Program C prints '5'.
- Program B prints '142'.
- Program B prints 'low'.
- Program C prints '6'.
- Program A prints '3'.
Explanation
Correct Answers
A:Running Program C prints '5'. A for loop visits each iterable element and can update a running accumulator on each pass.
B:Running Program B prints '142'. A for loop visits each iterable element and can update a running accumulator on each pass.
Incorrect Answers
C:Program B does not produce 'low'; its verified result is: Prints '142'. A for loop visits each iterable element and can update a running accumulator on each pass.
D:Program C does not produce '6'; its verified result is: Prints '5'. A for loop visits each iterable element and can update a running accumulator on each pass.
E:Program A does not produce '3'; its verified result is: Prints '6'. A for loop visits each iterable element and can update a running accumulator on each pass.
Question 129
A learner is checking while counter evolution. What is the exact printed result or uncaught exception?n=1
while n<5: n+=2
print(n)
- Prints '6'
- Prints '4'
- Prints '7'
- Prints '5'
Explanation
Correct Answer
D:The snippet prints '5'. A while loop retests its condition before every iteration and must update state to make progress.
Incorrect Answers
A:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '5'. A while loop retests its condition before every iteration and must update state to make progress.
B:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '5'. A while loop retests its condition before every iteration and must update state to make progress.
C:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '5'. A while loop retests its condition before every iteration and must update state to make progress.
Question 130
A developer tests while counter evolution. The following code prints '-2'. Which explanation best accounts for that observed behavior?n=6
while n>0: n-=4
print(n)
- Two separate if statements are tested independently; both can execute when both conditions are true.
- A for loop iterating over a string yields one-character strings in left-to-right order.
- continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
- A while loop retests its condition before every iteration and must update state to make progress.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints '-2'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The independent if branches topic does not explain why the code prints '-2'. The relevant Python rule is: A while loop retests its condition before every iteration and must update state to make progress.
B:The iteration over string characters topic does not explain why the code prints '-2'. The relevant Python rule is: A while loop retests its condition before every iteration and must update state to make progress.
C:The nested loop with conditional inner skip topic does not explain why the code prints '-2'. The relevant Python rule is: A while loop retests its condition before every iteration and must update state to make progress.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests