100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 160
During a review of nested for loops count Cartesian pairs, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
s=0
for i in range(2):
for j in range(3): s+=i+j
print(s)
Program B:
out=[]
for a in "ab":
for b in "xy": out.append(a+b)
print(out)
Program C:
n=0
for i in range(3):
for j in range(i): n+=1
print(n)
- Program C prints '6'.
- Program B prints "['ax', 'ay', 'bx', 'by']".
- Program C prints '3'.
- Program A prints '9'.
- Program B prints '[(1, 2), (1, 3), (2, 3)]'.
- Program A prints '4'.
Explanation
Correct Answers
B:Running Program B prints "['ax', 'ay', 'bx', 'by']". Every outer iteration starts a full inner loop unless control flow explicitly interrupts it.
C:Running Program C prints '3'. Every outer iteration starts a full inner loop unless control flow explicitly interrupts it.
D:Running Program A prints '9'. Every outer iteration starts a full inner loop unless control flow explicitly interrupts it.
Incorrect Answers
A:Program C does not produce '6'; its verified result is: Prints '3'. Every outer iteration starts a full inner loop unless control flow explicitly interrupts it.
E:Program B does not produce '[(1, 2), (1, 3), (2, 3)]'; its verified result is: Prints "['ax', 'ay', 'bx', 'by']". Every outer iteration starts a full inner loop unless control flow explicitly interrupts it.
F:Program A does not produce '4'; its verified result is: Prints '9'. Every outer iteration starts a full inner loop unless control flow explicitly interrupts it.
Question 161
A learner is checking break in a nested inner loop. What is the exact printed result or uncaught exception?out=[]
for i in range(3):
for j in range(4):
if j==2: break
out.append((i,j))
print(len(out))
- Prints '8'
- Prints '6'
- Prints '7'
- Prints '5'
Explanation
Correct Answer
B:The snippet prints '6'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
Incorrect Answers
A:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '6'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
C:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '6'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
D:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '6'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
Question 162
A developer tests break in a nested inner loop. The following code prints '3'. Which explanation best accounts for that observed behavior?s=0
for i in (1,2):
for j in (1,2,3):
if j==2: break
s+=i
print(s)
- A for loop iterating over a string yields one-character strings in left-to-right order.
- A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
- The not operator inverts truthiness; it does not numerically negate an operand.
- 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 '3'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The iteration over string characters topic does not explain why the code prints '3'. The relevant Python rule is: A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
C:The not reverses Boolean conditions topic does not explain why the code prints '3'. The relevant Python rule is: A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
D:The break terminates the nearest loop topic does not explain why the code prints '3'. The relevant Python rule is: A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
Question 163
A learner is checking break in a nested inner loop. After this modification, what does Python 3 actually do?out=[]
for x in (1,2):
for y in (4,5):
if y==5: break
out.append(x*y)
print(out)
- Prints '[8, 4]'
- Prints '[8]'
- Prints '[4]'
- Prints '[4, 8]'
Explanation
Correct Answer
D:The snippet prints '[4, 8]'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
Incorrect Answers
A:This predicts that the snippet prints '[8, 4]', but executing the displayed Python 3 code prints '[4, 8]'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
B:This predicts that the snippet prints '[8]', but executing the displayed Python 3 code prints '[4, 8]'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
C:This predicts that the snippet prints '[4]', but executing the displayed Python 3 code prints '[4, 8]'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
Question 164
During a review of break in a nested inner loop, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
s=0
for i in (1,2):
for j in (1,2,3):
if j==2: break
s+=i
print(s)
Program B:
out=[]
for x in (1,2):
for y in (4,5):
if y==5: break
out.append(x*y)
print(out)
Program C:
n=0
for i in range(4):
for j in range(2):
if j==0: break
n+=1
print(n)
- Program A prints '3'.
- Program C prints '0'.
- Program B prints '(1, 2)'.
- Program A prints '6'.
- Program B prints '[4, 8]'.
- Program C prints '2'.
Explanation
Correct Answers
A:Running Program A prints '3'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
B:Running Program C prints '0'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
E:Running Program B prints '[4, 8]'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
Incorrect Answers
C:Program B does not produce '(1, 2)'; its verified result is: Prints '[4, 8]'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
D:Program A does not produce '6'; its verified result is: Prints '3'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
F:Program C does not produce '2'; its verified result is: Prints '0'. A break inside the inner loop ends only that inner loop; the enclosing outer loop continues.
Question 165
A learner is checking pass as a no-op placeholder. What is the exact printed result or uncaught exception?x=3
if x>0: pass
print(x)
- Prints '2'
- Prints '5'
- Prints '4'
- Prints '3'
Explanation
Correct Answer
D:The snippet prints '3'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Incorrect Answers
A:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints '3'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
B:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '3'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
C:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '3'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Question 166
A developer tests pass as a no-op placeholder. The following code prints '3'. Which explanation best accounts for that observed behavior?total=0
for i in range(3):
pass
total+=i
print(total)
- pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
- A disjunction using or is true if either condition is true, including when the other is false.
- A for loop visits each iterable element and can update a running accumulator on each pass.
- 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 '3'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The or branch accepts either condition topic does not explain why the code prints '3'. The relevant Python rule is: pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
C:The for loop accumulating a sum topic does not explain why the code prints '3'. The relevant Python rule is: pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
D:The iteration over string characters topic does not explain why the code prints '3'. The relevant Python rule is: pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Question 167
A learner is checking pass as a no-op placeholder. After this modification, what does Python 3 actually do?flag=True
if flag: pass
else: print("off")
print("end")
- Prints 'end?'
- Prints 'dne'
- Prints 'en'
- Prints 'end'
Explanation
Correct Answer
D:The snippet prints 'end'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Incorrect Answers
A:This predicts that the snippet prints 'end?', but executing the displayed Python 3 code prints 'end'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
B:This predicts that the snippet prints 'dne', but executing the displayed Python 3 code prints 'end'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
C:This predicts that the snippet prints 'en', but executing the displayed Python 3 code prints 'end'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Question 168
During a review of pass as a no-op placeholder, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
total=0
for i in range(3):
pass
total+=i
print(total)
Program B:
flag=True
if flag: pass
else: print("off")
print("end")
Program C:
x=8
while x<9:
pass
x+=1
print(x)
- Program B prints 'end'.
- Program A prints '1'.
- Program C prints '9'.
- Program A prints '3'.
- Program B prints 'low'.
- Program C prints '3'.
Explanation
Correct Answers
A:Running Program B prints 'end'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
C:Running Program C prints '9'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
D:Running Program A prints '3'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Incorrect Answers
B:Program A does not produce '1'; its verified result is: Prints '3'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
E:Program B does not produce 'low'; its verified result is: Prints 'end'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
F:Program C does not produce '3'; its verified result is: Prints '9'. pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
Question 169
A learner is checking iteration over string characters. What is the exact printed result or uncaught exception?s=""
for c in "dog": s=c+s
print(s)
- Prints 'god?'
- Prints 'dog'
- Prints 'go'
- Prints 'god'
Explanation
Correct Answer
D:The snippet prints 'god'. A for loop iterating over a string yields one-character strings in left-to-right order.
Incorrect Answers
A:This predicts that the snippet prints 'god?', but executing the displayed Python 3 code prints 'god'. A for loop iterating over a string yields one-character strings in left-to-right order.
B:This predicts that the snippet prints 'dog', but executing the displayed Python 3 code prints 'god'. A for loop iterating over a string yields one-character strings in left-to-right order.
C:This predicts that the snippet prints 'go', but executing the displayed Python 3 code prints 'god'. A for loop iterating over a string yields one-character strings in left-to-right order.
Question 170
A developer tests iteration over string characters. The following code prints '3'. Which explanation best accounts for that observed behavior?n=0
for c in "banana":
if c=="a": n+=1
print(n)
- continue skips the remaining body of the current iteration but does not end the whole loop.
- A for loop else suite runs when the loop ends normally rather than because of break.
- pass does not alter variables or stop execution; it merely provides a syntactically valid empty statement.
- A for loop iterating over a string yields one-character strings in left-to-right order.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints '3'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The continue skips the rest of one loop pass topic does not explain why the code prints '3'. The relevant Python rule is: A for loop iterating over a string yields one-character strings in left-to-right order.
B:The for else after natural completion topic does not explain why the code prints '3'. The relevant Python rule is: A for loop iterating over a string yields one-character strings in left-to-right order.
C:The pass as a no-op placeholder topic does not explain why the code prints '3'. The relevant Python rule is: A for loop iterating over a string yields one-character strings in left-to-right order.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests