100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 140
During a review of continue skips the rest of one loop pass, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
s=0
for x in range(1,6):
if x==3: continue
s+=x
print(s)
Program B:
out=""
for c in "a-b-c":
if c=="-": continue
out+=c
print(out)
Program C:
nums=[]
for n in (1,2,3,4):
if n<3: continue
nums.append(n*n)
print(nums)
- Program C prints 'skipped'.
- Program B prints 'abc'.
- Program C prints '[9, 16]'.
- Program B prints 'end'.
- Program A prints 'on'.
Explanation
Correct Answers
B:Running Program B prints 'abc'. continue skips the remaining body of the current iteration but does not end the whole loop.
C:Running Program C prints '[9, 16]'. continue skips the remaining body of the current iteration but does not end the whole loop.
Incorrect Answers
A:Program C does not produce 'skipped'; its verified result is: Prints '[9, 16]'. continue skips the remaining body of the current iteration but does not end the whole loop.
D:Program B does not produce 'end'; its verified result is: Prints 'abc'. continue skips the remaining body of the current iteration but does not end the whole loop.
E:Program A does not produce 'on'; its verified result is: Prints '12'. continue skips the remaining body of the current iteration but does not end the whole loop.
Question 141
A learner is checking break terminates the nearest loop. What is the exact printed result or uncaught exception?seen=[]
for x in range(6):
if x==3: break
seen.append(x)
print(seen)
- Prints '[1, 2]'
- Prints '[0, 1, 2]'
- Prints '[2, 1, 0]'
- Prints '[0, 1]'
Explanation
Correct Answer
B:The snippet prints '[0, 1, 2]'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Incorrect Answers
A:This predicts that the snippet prints '[1, 2]', but executing the displayed Python 3 code prints '[0, 1, 2]'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
C:This predicts that the snippet prints '[2, 1, 0]', but executing the displayed Python 3 code prints '[0, 1, 2]'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
D:This predicts that the snippet prints '[0, 1]', but executing the displayed Python 3 code prints '[0, 1, 2]'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Question 142
A developer tests break terminates the nearest loop. The following code prints '6'. Which explanation best accounts for that observed behavior?s=0
for i in (2,4,7,8):
if i%2: break
s+=i
print(s)
- A for loop visits each iterable element and can update a running accumulator on each pass.
- range excludes its stop argument, so range(n) runs from zero through n-1.
- break exits its nearest enclosing loop immediately, without executing subsequent iterations.
- The in operator tests membership in a sequence or collection, not positional arithmetic equality.
Explanation
Correct Answer
C: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 loop accumulating a sum topic does not explain why the code prints '6'. The relevant Python rule is: break exits its nearest enclosing loop immediately, without executing subsequent iterations.
B:The range stop is exclusive topic does not explain why the code prints '6'. The relevant Python rule is: break exits its nearest enclosing loop immediately, without executing subsequent iterations.
D:The membership-based conditional topic does not explain why the code prints '6'. The relevant Python rule is: break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Question 143
A learner is checking break terminates the nearest loop. After this modification, what does Python 3 actually do?n=5
while n>0:
if n==2: break
n-=1
print(n)
- Prints '4'
- Prints '1'
- Prints '2'
- Prints '3'
Explanation
Correct Answer
C:The snippet prints '2'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Incorrect Answers
A:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '2'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
B:This predicts that the snippet prints '1', but executing the displayed Python 3 code prints '2'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
D:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '2'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Question 144
During a review of break terminates the nearest loop, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
s=0
for i in (2,4,7,8):
if i%2: break
s+=i
print(s)
Program B:
n=5
while n>0:
if n==2: break
n-=1
print(n)
Program C:
for k in range(4):
if k==0: break
print("stopped")
- Program A prints '4'.
- Program B prints '2'.
- Program B prints 'i'.
- Program C prints 'allowed'.
- Program C prints 'stopped'.
- Program A prints '6'.
Explanation
Correct Answers
B:Running Program B prints '2'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
E:Running Program C prints 'stopped'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
F:Running Program A prints '6'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Incorrect Answers
A:Program A does not produce '4'; its verified result is: Prints '6'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
C:Program B does not produce 'i'; its verified result is: Prints '2'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
D:Program C does not produce 'allowed'; its verified result is: Prints 'stopped'. break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Question 145
A learner is checking for else after natural completion. What is the exact printed result or uncaught exception?for x in range(3): print(x,end="")
else: print(" done")
- Prints '012 done'
- Prints '012 don'
- Prints '012 done?'
- Prints 'enod 210'
Explanation
Correct Answer
A:The snippet prints '012 done'. A for loop else suite runs when the loop ends normally rather than because of break.
Incorrect Answers
B:This predicts that the snippet prints '012 don', but executing the displayed Python 3 code prints '012 done'. A for loop else suite runs when the loop ends normally rather than because of break.
C:This predicts that the snippet prints '012 done?', but executing the displayed Python 3 code prints '012 done'. A for loop else suite runs when the loop ends normally rather than because of break.
D:This predicts that the snippet prints 'enod 210', but executing the displayed Python 3 code prints '012 done'. A for loop else suite runs when the loop ends normally rather than because of break.
Question 146
A developer tests for else after natural completion. The following code prints 'empty done'. Which explanation best accounts for that observed behavior?for x in []: print("body")
else: print("empty done")
- A for loop else suite runs when the loop ends normally rather than because of break.
- The third range argument controls the step, and the stop endpoint remains excluded.
- A Python for loop target remains bound to the last visited value after a nonempty loop.
- A for loop iterating over a string yields one-character strings in left-to-right order.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints 'empty done'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The range with positive step topic does not explain why the code prints 'empty done'. The relevant Python rule is: A for loop else suite runs when the loop ends normally rather than because of break.
C:The loop index persists after normal completion topic does not explain why the code prints 'empty done'. The relevant Python rule is: A for loop else suite runs when the loop ends normally rather than because of break.
D:The iteration over string characters topic does not explain why the code prints 'empty done'. The relevant Python rule is: A for loop else suite runs when the loop ends normally rather than because of break.
Question 147
A learner is checking for else after natural completion. After this modification, what does Python 3 actually do?for ch in "xy": pass
else: print("complete")
- Prints 'complet'
- Prints 'complete?'
- Prints 'etelpmoc'
- Prints 'complete'
Explanation
Correct Answer
D:The snippet prints 'complete'. A for loop else suite runs when the loop ends normally rather than because of break.
Incorrect Answers
A:This predicts that the snippet prints 'complet', but executing the displayed Python 3 code prints 'complete'. A for loop else suite runs when the loop ends normally rather than because of break.
B:This predicts that the snippet prints 'complete?', but executing the displayed Python 3 code prints 'complete'. A for loop else suite runs when the loop ends normally rather than because of break.
C:This predicts that the snippet prints 'etelpmoc', but executing the displayed Python 3 code prints 'complete'. A for loop else suite runs when the loop ends normally rather than because of break.
Question 148
During a review of for else after natural completion, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
for x in []: print("body")
else: print("empty done")
Program B:
for ch in "xy": pass
else: print("complete")
Program C:
for x in (1,2):
if x>4: break
else: print("not found")
- Program B prints 'complete'.
- Program C prints 'small odd'.
- Program B prints 'odd high'.
- Program A prints 'empty done'.
- Program C prints 'not found'.
- Program A prints 'inner else'.
Explanation
Correct Answers
A:Running Program B prints 'complete'. A for loop else suite runs when the loop ends normally rather than because of break.
D:Running Program A prints 'empty done'. A for loop else suite runs when the loop ends normally rather than because of break.
E:Running Program C prints 'not found'. A for loop else suite runs when the loop ends normally rather than because of break.
Incorrect Answers
B:Program C does not produce 'small odd'; its verified result is: Prints 'not found'. A for loop else suite runs when the loop ends normally rather than because of break.
C:Program B does not produce 'odd high'; its verified result is: Prints 'complete'. A for loop else suite runs when the loop ends normally rather than because of break.
F:Program A does not produce 'inner else'; its verified result is: Prints 'empty done'. A for loop else suite runs when the loop ends normally rather than because of break.
Question 149
A learner is checking for else suppressed by break. What is the exact printed result or uncaught exception?for i in (1,2,3):
if i==2: break
else: print("else")
print("done")
- Prints 'done?'
- Prints 'done'
- Prints 'enod'
- Prints 'don'
Explanation
Correct Answer
B:The snippet prints 'done'. A for loop else clause does not run when a break ends the loop early.
Incorrect Answers
A:This predicts that the snippet prints 'done?', but executing the displayed Python 3 code prints 'done'. A for loop else clause does not run when a break ends the loop early.
C:This predicts that the snippet prints 'enod', but executing the displayed Python 3 code prints 'done'. A for loop else clause does not run when a break ends the loop early.
D:This predicts that the snippet prints 'don', but executing the displayed Python 3 code prints 'done'. A for loop else clause does not run when a break ends the loop early.
Question 150
A developer tests for else suppressed by break. The following code prints 'end'. Which explanation best accounts for that observed behavior?for s in "cats":
if s=="t": break
else: print("no t")
print("end")
- A disjunction using or is true if either condition is true, including when the other is false.
- The in operator tests membership in a sequence or collection, not positional arithmetic equality.
- A for loop else clause does not run when a break ends the loop early.
- break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints 'end'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The or branch accepts either condition topic does not explain why the code prints 'end'. The relevant Python rule is: A for loop else clause does not run when a break ends the loop early.
B:The membership-based conditional topic does not explain why the code prints 'end'. The relevant Python rule is: A for loop else clause does not run when a break ends the loop early.
D:The break terminates the nearest loop topic does not explain why the code prints 'end'. The relevant Python rule is: A for loop else clause does not run when a break ends the loop early.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests