100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 300
A learner is checking early return versus later statements. Which final result follows from this separate test?def f(x):
if x<0: return -x
return x
print(f(-7))
- Prints '9'
- Prints '8'
- Prints '6'
- Prints '7'
Explanation
Correct Answer
D:The snippet prints '7'. Once a function returns, the remaining statements in that function call are not executed.
Incorrect Answers
A:This predicts that the snippet prints '9', but executing the displayed Python 3 code prints '7'. Once a function returns, the remaining statements in that function call are not executed.
B:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '7'. Once a function returns, the remaining statements in that function call are not executed.
C:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '7'. Once a function returns, the remaining statements in that function call are not executed.
Question 301
A learner is checking function call composition. What is the exact printed result or uncaught exception?def f(x): return x+2
def g(x): return x*3
print(g(f(2)))
- Prints '13'
- Prints '14'
- Prints '12'
- Prints '11'
Explanation
Correct Answer
C:The snippet prints '12'. The result returned by one function can be passed directly as an argument to another function.
Incorrect Answers
A:This predicts that the snippet prints '13', but executing the displayed Python 3 code prints '12'. The result returned by one function can be passed directly as an argument to another function.
B:This predicts that the snippet prints '14', but executing the displayed Python 3 code prints '12'. The result returned by one function can be passed directly as an argument to another function.
D:This predicts that the snippet prints '11', but executing the displayed Python 3 code prints '12'. The result returned by one function can be passed directly as an argument to another function.
Question 302
A developer tests function call composition. The following code prints '8'. Which explanation best accounts for that observed behavior?def f(x): return x*2
def g(x): return x-1
print(f(g(5)))
- Positional arguments bind to parameters in declared order; their values are not automatically sorted or swapped.
- A generator yields values lazily and resumes after each yield when next is called.
- The result returned by one function can be passed directly as an argument to another function.
- KeyboardInterrupt and SystemExit derive from BaseException but not from the Exception subclass.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints '8'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The positional argument binding topic does not explain why the code prints '8'. The relevant Python rule is: The result returned by one function can be passed directly as an argument to another function.
B:The generator yield suspends state topic does not explain why the code prints '8'. The relevant Python rule is: The result returned by one function can be passed directly as an argument to another function.
D:The BaseException versus Exception topic does not explain why the code prints '8'. The relevant Python rule is: The result returned by one function can be passed directly as an argument to another function.
Question 303
A learner is checking function call composition. After this modification, what does Python 3 actually do?def square(x): return x*x
def total(a,b): return a+b
print(total(square(2),3))
- Prints '7'
- Prints '9'
- Prints '8'
- Prints '6'
Explanation
Correct Answer
A:The snippet prints '7'. The result returned by one function can be passed directly as an argument to another function.
Incorrect Answers
B:This predicts that the snippet prints '9', but executing the displayed Python 3 code prints '7'. The result returned by one function can be passed directly as an argument to another function.
C:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '7'. The result returned by one function can be passed directly as an argument to another function.
D:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '7'. The result returned by one function can be passed directly as an argument to another function.
Question 304
A learner is checking function call composition. Which final result follows from this separate test?def inc(x): return x+1
print(inc(inc(3)))
- Prints '4'
- Prints '6'
- Prints '5'
- Prints '7'
Explanation
Correct Answer
C:The snippet prints '5'. The result returned by one function can be passed directly as an argument to another function.
Incorrect Answers
A:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '5'. The result returned by one function can be passed directly as an argument to another function.
B:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '5'. The result returned by one function can be passed directly as an argument to another function.
D:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '5'. The result returned by one function can be passed directly as an argument to another function.
Question 305
A learner is checking recursive factorial base case. What is the exact printed result or uncaught exception?def fact(n):
if n<=1: return 1
return n*fact(n-1)
print(fact(4))
- Prints '23'
- Prints '26'
- Prints '24'
- Prints '25'
Explanation
Correct Answer
C:The snippet prints '24'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
Incorrect Answers
A:This predicts that the snippet prints '23', but executing the displayed Python 3 code prints '24'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
B:This predicts that the snippet prints '26', but executing the displayed Python 3 code prints '24'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
D:This predicts that the snippet prints '25', but executing the displayed Python 3 code prints '24'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
Question 306
A developer tests recursive factorial base case. The following code prints '6'. Which explanation best accounts for that observed behavior?def fact(n):
if n<=1: return 1
return n*fact(n-1)
print(fact(3))
- A return statement immediately exits a function and supplies its expression as the call result.
- An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
- A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
- A function modifying a list argument in place changes the same list observed by its caller.
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 function return controls result topic does not explain why the code prints '6'. The relevant Python rule is: A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
B:The specific versus incorrect exception catch topic does not explain why the code prints '6'. The relevant Python rule is: A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
D:The mutable list argument shared with caller topic does not explain why the code prints '6'. The relevant Python rule is: A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
Question 307
A learner is checking recursive factorial base case. After this modification, what does Python 3 actually do?def fact(n):
if n<=1: return 1
return n*fact(n-1)
print(fact(0))
- Prints '2'
- Prints '3'
- Prints '0'
- Prints '1'
Explanation
Correct Answer
D:The snippet prints '1'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
Incorrect Answers
A:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints '1'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
B:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '1'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
C:This predicts that the snippet prints '0', but executing the displayed Python 3 code prints '1'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
Question 308
A learner is checking recursive factorial base case. Which final result follows from this separate test?def fact(n):
if n<=1: return 1
return n*fact(n-1)
print(fact(5))
- Prints '121'
- Prints '119'
- Prints '122'
- Prints '120'
Explanation
Correct Answer
D:The snippet prints '120'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
Incorrect Answers
A:This predicts that the snippet prints '121', but executing the displayed Python 3 code prints '120'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
B:This predicts that the snippet prints '119', but executing the displayed Python 3 code prints '120'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
C:This predicts that the snippet prints '122', but executing the displayed Python 3 code prints '120'. A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
Question 309
A learner is checking recursive summation. What is the exact printed result or uncaught exception?def f(n):
if n==0: return 0
return n+f(n-1)
print(f(4))
- Prints '9'
- Prints '10'
- Prints '12'
- Prints '11'
Explanation
Correct Answer
B:The snippet prints '10'. 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 '9', but executing the displayed Python 3 code prints '10'. 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 '12', but executing the displayed Python 3 code prints '10'. 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 '11', but executing the displayed Python 3 code prints '10'. A recursive sum decreases the input until its base case and combines each return value on the way back.
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.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests