100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 180
During a review of sentinel-controlled while loop, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
numbers=(4,3,-1,8)
i=0
while True:
if numbers[i]<0: break
i+=1
print(i)
Program B:
values=["ok","ok","stop"]
k=0
while True:
if values[k]=="stop": break
k+=1
print(k)
Program C:
items=(1,0,2)
i=0
while True:
if items[i]==0: break
i+=1
print(items[i])
- Program C prints '0'.
- Program A prints '2'.
- Program B prints '2'.
- Program B prints '0'.
- Program C prints '2'.
- Program A prints '0'.
Explanation
Correct Answers
A:Running Program C prints '0'. A sentinel test can terminate an otherwise indefinite while loop after the sentinel value is reached.
B:Running Program A prints '2'. A sentinel test can terminate an otherwise indefinite while loop after the sentinel value is reached.
C:Running Program B prints '2'. A sentinel test can terminate an otherwise indefinite while loop after the sentinel value is reached.
Incorrect Answers
D:Program B does not produce '0'; its verified result is: Prints '2'. A sentinel test can terminate an otherwise indefinite while loop after the sentinel value is reached.
E:Program C does not produce '2'; its verified result is: Prints '0'. A sentinel test can terminate an otherwise indefinite while loop after the sentinel value is reached.
F:Program A does not produce '0'; its verified result is: Prints '2'. A sentinel test can terminate an otherwise indefinite while loop after the sentinel value is reached.
Question 181
A learner is checking nested loop with conditional inner skip. What is the exact printed result or uncaught exception?s=0
for i in range(2):
for j in range(3):
if j==1: continue
s+=i+j
print(s)
- Prints '8'
- Prints '6'
- Prints '7'
- Prints '5'
Explanation
Correct Answer
B:The snippet prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
Incorrect Answers
A:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
C:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
D:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
Question 182
A developer tests nested loop with conditional inner skip. The following code prints '[(1, 2), (1, 3), (2, 3)]'. Which explanation best accounts for that observed behavior?out=[]
for a in (1,2):
for b in (2,3):
if a==b: continue
out.append((a,b))
print(out)
- A sentinel test can terminate an otherwise indefinite while loop after the sentinel value is reached.
- continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
- A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
- An else block belongs to its indentation-level if; nested else is not automatically the outer else.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '[(1, 2), (1, 3), (2, 3)]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The sentinel-controlled while loop topic does not explain why the code prints '[(1, 2), (1, 3), (2, 3)]'. The relevant Python rule is: continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
C:The break in a nested inner loop topic does not explain why the code prints '[(1, 2), (1, 3), (2, 3)]'. The relevant Python rule is: continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
D:The which else belongs to if topic does not explain why the code prints '[(1, 2), (1, 3), (2, 3)]'. The relevant Python rule is: continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
Question 183
A learner is checking nested loop with conditional inner skip. After this modification, what does Python 3 actually do?count=0
for i in range(3):
for j in range(3):
if i==j: continue
count+=1
print(count)
- Prints '7'
- Prints '8'
- Prints '6'
- Prints '5'
Explanation
Correct Answer
C:The snippet prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
Incorrect Answers
A:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
B:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
D:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
Question 184
During a review of nested loop with conditional inner skip, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
out=[]
for a in (1,2):
for b in (2,3):
if a==b: continue
out.append((a,b))
print(out)
Program B:
count=0
for i in range(3):
for j in range(3):
if i==j: continue
count+=1
print(count)
Program C:
total=0
for a in (1,2):
for b in (3,4):
if b==4: continue
total+=a*b
print(total)
- Program C prints '9'.
- Program B prints '6'.
- Program A prints "['ax', 'ay', 'bx', 'by']".
- Program B prints '2'.
- Program C prints 'i'.
- Program A prints '[(1, 2), (1, 3), (2, 3)]'.
Explanation
Correct Answers
A:Running Program C prints '9'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
B:Running Program B prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
F:Running Program A prints '[(1, 2), (1, 3), (2, 3)]'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
Incorrect Answers
C:Program A does not produce "['ax', 'ay', 'bx', 'by']"; its verified result is: Prints '[(1, 2), (1, 3), (2, 3)]'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
D:Program B does not produce '2'; its verified result is: Prints '6'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
E:Program C does not produce 'i'; its verified result is: Prints '9'. continue inside an inner loop skips one inner iteration while both loops otherwise proceed.
Question 185
A learner is checking loop index persists after normal completion. What is the exact printed result or uncaught exception?for x in [4,7,9]: pass
print(x)
- Prints '9'
- Prints '10'
- Prints '11'
- Prints '8'
Explanation
Correct Answer
A:The snippet prints '9'. A Python for loop target remains bound to the last visited value after a nonempty loop.
Incorrect Answers
B:This predicts that the snippet prints '10', but executing the displayed Python 3 code prints '9'. A Python for loop target remains bound to the last visited value after a nonempty loop.
C:This predicts that the snippet prints '11', but executing the displayed Python 3 code prints '9'. A Python for loop target remains bound to the last visited value after a nonempty loop.
D:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '9'. A Python for loop target remains bound to the last visited value after a nonempty loop.
Question 186
A developer tests loop index persists after normal completion. The following code prints '4'. Which explanation best accounts for that observed behavior?for n in range(1,5): pass
print(n)
- A for loop else clause does not run when a break ends the loop early.
- A Python for loop target remains bound to the last visited value after a nonempty loop.
- A for loop else suite runs when the loop ends normally rather than because of break.
- break exits its nearest enclosing loop immediately, without executing subsequent iterations.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '4'; 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 '4'. The relevant Python rule is: A Python for loop target remains bound to the last visited value after a nonempty loop.
C:The for else after natural completion topic does not explain why the code prints '4'. The relevant Python rule is: A Python for loop target remains bound to the last visited value after a nonempty loop.
D:The break terminates the nearest loop topic does not explain why the code prints '4'. The relevant Python rule is: A Python for loop target remains bound to the last visited value after a nonempty loop.
Question 187
A learner is checking loop index persists after normal completion. After this modification, what does Python 3 actually do?for ch in "hi": pass
print(ch)
- Prints ''
- Prints 'i'
- Prints 'i?'
- Prints 'I'
Explanation
Correct Answer
B:The snippet prints 'i'. A Python for loop target remains bound to the last visited value after a nonempty loop.
Incorrect Answers
A:This predicts that the snippet prints '', but executing the displayed Python 3 code prints 'i'. A Python for loop target remains bound to the last visited value after a nonempty loop.
C:This predicts that the snippet prints 'i?', but executing the displayed Python 3 code prints 'i'. A Python for loop target remains bound to the last visited value after a nonempty loop.
D:This predicts that the snippet prints 'i', but executing the displayed Python 3 code prints 'i'. A Python for loop target remains bound to the last visited value after a nonempty loop.
Question 188
During a review of loop index persists after normal completion, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
for n in range(1,5): pass
print(n)
Program B:
for ch in "hi": pass
print(ch)
Program C:
total=0
for i in range(3): total+=i
print(i,total)
- Program B prints 'i'.
- Program A prints '7'.
- Program A prints '4'.
- Program B prints '0'.
- Program C prints '2 3'.
- Program C prints 'neg'.
Explanation
Correct Answers
A:Running Program B prints 'i'. A Python for loop target remains bound to the last visited value after a nonempty loop.
C:Running Program A prints '4'. A Python for loop target remains bound to the last visited value after a nonempty loop.
E:Running Program C prints '2 3'. A Python for loop target remains bound to the last visited value after a nonempty loop.
Incorrect Answers
B:Program A does not produce '7'; its verified result is: Prints '4'. A Python for loop target remains bound to the last visited value after a nonempty loop.
D:Program B does not produce '0'; its verified result is: Prints 'i'. A Python for loop target remains bound to the last visited value after a nonempty loop.
F:Program C does not produce 'neg'; its verified result is: Prints '2 3'. A Python for loop target remains bound to the last visited value after a nonempty loop.
Question 189
A learner is checking negative list indices. What is the exact printed result or uncaught exception?data=[10,20,30]
print(data[-1])
- Prints '32'
- Prints '30'
- Prints '31'
- Prints '29'
Explanation
Correct Answer
B:The snippet prints '30'. Negative list indices count backward from the end, with -1 selecting the last element.
Incorrect Answers
A:This predicts that the snippet prints '32', but executing the displayed Python 3 code prints '30'. Negative list indices count backward from the end, with -1 selecting the last element.
C:This predicts that the snippet prints '31', but executing the displayed Python 3 code prints '30'. Negative list indices count backward from the end, with -1 selecting the last element.
D:This predicts that the snippet prints '29', but executing the displayed Python 3 code prints '30'. Negative list indices count backward from the end, with -1 selecting the last element.
Question 190
A developer tests negative list indices. The following code prints 'b'. Which explanation best accounts for that observed behavior?letters=["a","b","c","d"]
print(letters[-3])
- Negative list indices count backward from the end, with -1 selecting the last element.
- List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
- String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
- split converts a string to parts using a delimiter; join combines string parts with a separator.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints 'b'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The list slicing excludes stop topic does not explain why the code prints 'b'. The relevant Python rule is: Negative list indices count backward from the end, with -1 selecting the last element.
C:The string negative indexing and slices topic does not explain why the code prints 'b'. The relevant Python rule is: Negative list indices count backward from the end, with -1 selecting the last element.
D:The split and join strings topic does not explain why the code prints 'b'. The relevant Python rule is: Negative list indices count backward from the end, with -1 selecting the last element.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests