100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 310
A developer tests recursive summation. The following code prints '6'. Which explanation best accounts for that observed behavior?def f(n):
if n<=1: return n
return n+f(n-1)
print(f(3))
- A recursive sum decreases the input until its base case and combines each return value on the way back.
- Keyword arguments bind by parameter name regardless of the order in which keywords are written.
- Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
- A return statement immediately exits a function and supplies its expression as the call result.
Explanation
Correct Answer
A: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
B:The keyword argument binding topic does not explain why the code prints '6'. The relevant Python rule is: A recursive sum decreases the input until its base case and combines each return value on the way back.
C:The positional argument binding topic does not explain why the code prints '6'. The relevant Python rule is: A recursive sum decreases the input until its base case and combines each return value on the way back.
D:The function return controls result topic does not explain why the code prints '6'. The relevant Python rule is: A recursive sum decreases the input until its base case and combines each return value on the way back.
Question 311
A learner is checking recursive summation. After this modification, what does Python 3 actually do?def f(n):
if n==0: return 0
return 2+f(n-1)
print(f(3))
- Prints '7'
- Prints '6'
- Prints '5'
- Prints '8'
Explanation
Correct Answer
B:The snippet prints '6'. A recursive sum decreases the input until its base case and combines each return value on the way back.
Incorrect Answers
A:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '6'. A recursive sum decreases the input until its base case and combines each return value on the way back.
C:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '6'. A recursive sum decreases the input until its base case and combines each return value on the way back.
D:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '6'. A recursive sum decreases the input until its base case and combines each return value on the way back.
Question 312
A learner is checking recursive summation. Which final result follows from this separate test?def f(n):
if n==0: return 1
return 2*f(n-1)
print(f(4))
- Prints '16'
- Prints '18'
- Prints '17'
- Prints '15'
Explanation
Correct Answer
A:The snippet prints '16'. A recursive sum decreases the input until its base case and combines each return value on the way back.
Incorrect Answers
B:This predicts that the snippet prints '18', but executing the displayed Python 3 code prints '16'. A recursive sum decreases the input until its base case and combines each return value on the way back.
C:This predicts that the snippet prints '17', but executing the displayed Python 3 code prints '16'. A recursive sum decreases the input until its base case and combines each return value on the way back.
D:This predicts that the snippet prints '15', but executing the displayed Python 3 code prints '16'. A recursive sum decreases the input until its base case and combines each return value on the way back.
Question 313
A learner is checking generator yield suspends state. What is the exact printed result or uncaught exception?def g():
yield 2
yield 5
it=g()
print(next(it),next(it))
- Prints '5 2'
- Prints '2 '
- Prints '2 5?'
- Prints '2 5'
Explanation
Correct Answer
D:The snippet prints '2 5'. A generator yields values lazily and resumes after each yield when next is called.
Incorrect Answers
A:This predicts that the snippet prints '5 2', but executing the displayed Python 3 code prints '2 5'. A generator yields values lazily and resumes after each yield when next is called.
B:This predicts that the snippet prints '2 ', but executing the displayed Python 3 code prints '2 5'. A generator yields values lazily and resumes after each yield when next is called.
C:This predicts that the snippet prints '2 5?', but executing the displayed Python 3 code prints '2 5'. A generator yields values lazily and resumes after each yield when next is called.
Question 314
A developer tests generator yield suspends state. The following code prints "['a', 'b']". Which explanation best accounts for that observed behavior?def g():
yield "a"
yield "b"
print(list(g()))
- A generator yields values lazily and resumes after each yield when next is called.
- The except clause matching the raised exception class handles the error and allows execution to continue.
- KeyboardInterrupt and SystemExit derive from BaseException but not from the Exception subclass.
- ZeroDivisionError inherits from ArithmeticError which itself inherits from Exception.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints "['a', 'b']"; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The exact exception handler selection topic does not explain why the code prints "['a', 'b']". The relevant Python rule is: A generator yields values lazily and resumes after each yield when next is called.
C:The BaseException versus Exception topic does not explain why the code prints "['a', 'b']". The relevant Python rule is: A generator yields values lazily and resumes after each yield when next is called.
D:The ArithmeticError inheritance topic does not explain why the code prints "['a', 'b']". The relevant Python rule is: A generator yields values lazily and resumes after each yield when next is called.
Question 315
A learner is checking generator yield suspends state. After this modification, what does Python 3 actually do?def g():
yield 7
it=g()
next(it)
print(next(it))
- Raises TypeError
- Raises StopIteration
- Raises KeyError
- Raises IndexError
Explanation
Correct Answer
B:The snippet raises stopiteration. A generator yields values lazily and resumes after each yield when next is called.
Incorrect Answers
A:This predicts that the snippet raises typeerror, but executing the displayed Python 3 code raises stopiteration. A generator yields values lazily and resumes after each yield when next is called.
C:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises stopiteration. A generator yields values lazily and resumes after each yield when next is called.
D:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises stopiteration. A generator yields values lazily and resumes after each yield when next is called.
Question 316
During a review of generator yield suspends state, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def g():
yield "a"
yield "b"
print(list(g()))
Program B:
def g():
yield 7
it=g()
next(it)
print(next(it))
Program C:
def g():
yield 1
yield 2
it=g()
print(next(it))
- Program A prints 'left:right'.
- Program C prints '5'.
- Program C prints '1'.
- Program B prints 'bad integer'.
- Program B raises stopiteration.
Explanation
Correct Answers
C:Running Program C prints '1'. A generator yields values lazily and resumes after each yield when next is called.
E:Running Program B raises stopiteration. A generator yields values lazily and resumes after each yield when next is called.
Incorrect Answers
A:Program A does not produce 'left:right'; its verified result is: Prints "['a', 'b']". A generator yields values lazily and resumes after each yield when next is called.
B:Program C does not produce '5'; its verified result is: Prints '1'. A generator yields values lazily and resumes after each yield when next is called.
D:Program B does not produce 'bad integer'; its verified result is: Raises StopIteration. A generator yields values lazily and resumes after each yield when next is called.
Question 317
A learner is checking yield inside for loop. What is the exact printed result or uncaught exception?def g():
for x in range(3): yield x*x
print(list(g()))
- Prints '[4, 1, 0]'
- Prints '[0, 1, 4]'
- Prints '[0, 1]'
- Prints '[1, 4]'
Explanation
Correct Answer
B:The snippet prints '[0, 1, 4]'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
Incorrect Answers
A:This predicts that the snippet prints '[4, 1, 0]', but executing the displayed Python 3 code prints '[0, 1, 4]'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
C:This predicts that the snippet prints '[0, 1]', but executing the displayed Python 3 code prints '[0, 1, 4]'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
D:This predicts that the snippet prints '[1, 4]', but executing the displayed Python 3 code prints '[0, 1, 4]'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
Question 318
A developer tests yield inside for loop. The following code prints '[3, 5]'. Which explanation best accounts for that observed behavior?def g():
for x in (2,4): yield x+1
print(list(g()))
- An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
- The result returned by one function can be passed directly as an argument to another function.
- A generator can yield one value per loop pass, and consumption determines how many iterations run.
- Once a function returns, the remaining statements in that function call are not executed.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints '[3, 5]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The specific versus incorrect exception catch topic does not explain why the code prints '[3, 5]'. The relevant Python rule is: A generator can yield one value per loop pass, and consumption determines how many iterations run.
B:The function call composition topic does not explain why the code prints '[3, 5]'. The relevant Python rule is: A generator can yield one value per loop pass, and consumption determines how many iterations run.
D:The early return versus later statements topic does not explain why the code prints '[3, 5]'. The relevant Python rule is: A generator can yield one value per loop pass, and consumption determines how many iterations run.
Question 319
A learner is checking yield inside for loop. After this modification, what does Python 3 actually do?def g():
for x in range(1,4): yield x
it=g()
print(next(it),next(it))
- Prints '1 '
- Prints '2 1'
- Prints '1 2'
- Prints '1 2?'
Explanation
Correct Answer
C:The snippet prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
Incorrect Answers
A:This predicts that the snippet prints '1 ', but executing the displayed Python 3 code prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
B:This predicts that the snippet prints '2 1', but executing the displayed Python 3 code prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
D:This predicts that the snippet prints '1 2?', but executing the displayed Python 3 code prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
Question 320
During a review of yield inside for loop, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def g():
for x in (2,4): yield x+1
print(list(g()))
Program B:
def g():
for x in range(1,4): yield x
it=g()
print(next(it),next(it))
Program C:
def g():
for c in "ab": yield c.upper()
print("".join(g()))
- Program B prints '120'.
- Program C prints 'ab'.
- Program B prints '1 2'.
- Program C prints '27'.
- Program A prints 'lookup'.
Explanation
Correct Answers
B:Running Program C prints 'ab'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
C:Running Program B prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
Incorrect Answers
A:Program B does not produce '120'; its verified result is: Prints '1 2'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
D:Program C does not produce '27'; its verified result is: Prints 'AB'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
E:Program A does not produce 'lookup'; its verified result is: Prints '[3, 5]'. A generator can yield one value per loop pass, and consumption determines how many iterations run.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests