100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 290
A developer tests function return controls result. The following code prints 'other'. Which explanation best accounts for that observed behavior?def f(n):
if n>0: return "pos"
return "other"
print(f(-1))
- Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
- A return statement immediately exits a function and supplies its expression as the call result.
- Providing a parameter both positionally and by keyword causes TypeError for multiple values.
- A generator can yield one value per loop pass, and consumption determines how many iterations run.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints 'other'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The local variable before assignment error topic does not explain why the code prints 'other'. The relevant Python rule is: A return statement immediately exits a function and supplies its expression as the call result.
C:The duplicate argument assignment raises TypeError topic does not explain why the code prints 'other'. The relevant Python rule is: A return statement immediately exits a function and supplies its expression as the call result.
D:The yield inside for loop topic does not explain why the code prints 'other'. The relevant Python rule is: A return statement immediately exits a function and supplies its expression as the call result.
Question 291
A learner is checking function return controls result. After this modification, what does Python 3 actually do?def f(x):
return x+1
print("never")
print(f(3))
- Prints '4'
- Prints '3'
- Prints '6'
- Prints '5'
Explanation
Correct Answer
A:The snippet prints '4'. A return statement immediately exits a function and supplies its expression as the call result.
Incorrect Answers
B:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '4'. A return statement immediately exits a function and supplies its expression as the call result.
C:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '4'. A return statement immediately exits a function and supplies its expression as the call result.
D:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '4'. A return statement immediately exits a function and supplies its expression as the call result.
Question 292
A learner is checking function return controls result. Which final result follows from this separate test?def add(a,b):
return a+b
print(add(2,5)*2)
- Prints '14'
- Prints '13'
- Prints '16'
- Prints '15'
Explanation
Correct Answer
A:The snippet prints '14'. A return statement immediately exits a function and supplies its expression as the call result.
Incorrect Answers
B:This predicts that the snippet prints '13', but executing the displayed Python 3 code prints '14'. A return statement immediately exits a function and supplies its expression as the call result.
C:This predicts that the snippet prints '16', but executing the displayed Python 3 code prints '14'. A return statement immediately exits a function and supplies its expression as the call result.
D:This predicts that the snippet prints '15', but executing the displayed Python 3 code prints '14'. A return statement immediately exits a function and supplies its expression as the call result.
Question 293
A learner is checking implicit None return. What is the exact printed result or uncaught exception?def f():
x=3
print(f())
- Prints 'None'
- Prints 'even'
- Prints 'True'
- Prints 'hi\nNone'
Explanation
Correct Answer
A:The snippet prints 'none'. A Python function without a reachable return statement returns the singleton None.
Incorrect Answers
B:This predicts that the snippet prints 'even', but executing the displayed Python 3 code prints 'none'. A Python function without a reachable return statement returns the singleton None.
C:This predicts that the snippetprints 'true', but executing the displayed Python 3 code prints 'none'. A Python function without a reachable return statement returns the singleton None.
D:This predicts that the snippet prints 'hi\nnone', but executing the displayed Python 3 code prints 'none'. A Python function without a reachable return statement returns the singleton None.
Question 294
A developer tests implicit None return. The following code prints 'hi\nnone'. Which explanation best accounts for that observed behavior?def log(x):
print(x)
r=log("hi")
print(r)
- A Python function without a reachable return statement returns the singleton None.
- A recursive sum decreases the input until its base case and combines each return value on the way back.
- Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
- int raises ValueError for text that cannot represent an integer; incompatible argument types raise TypeError.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints 'hi\nnone'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The recursive summation topic does not explain why the code prints 'hi\nnone'. The relevant Python rule is: A Python function without a reachable return statement returns the singleton None.
C:The first matching except branch topic does not explain why the code prints 'hi\nnone'. The relevant Python rule is: A Python function without a reachable return statement returns the singleton None.
D:The ValueError versus TypeError in conversion topic does not explain why the code prints 'hi\nnone'. The relevant Python rule is: A Python function without a reachable return statement returns the singleton None.
Question 295
A learner is checking implicit None return. After this modification, what does Python 3 actually do?def f(n):
if n>0: return n
print(f(0))
- Prints 'True'
- Prints 'None'
- Prints 'hi\nNone'
- Prints 'even'
Explanation
Correct Answer
B:The snippet prints 'none'. A Python function without a reachable return statement returns the singleton None.
Incorrect Answers
A:This predicts that the snippetprints 'true', but executing the displayed Python 3 code prints 'none'. A Python function without a reachable return statement returns the singleton None.
C:This predicts that the snippet prints 'hi\nnone', but executing the displayed Python 3 code prints 'none'. A Python function without a reachable return statement returns the singleton None.
D:This predicts that the snippet prints 'even', but executing the displayed Python 3 code prints 'none'. A Python function without a reachable return statement returns the singleton None.
Question 296
A learner is checking implicit None return. Which final result follows from this separate test?def g():
pass
print(g() is None)
- Prints 'True'
- Prints '1'
- Prints 'False'
- Prints '0'
Explanation
Correct Answer
A:The snippetprints 'true'. A Python function without a reachable return statement returns the singleton None.
Incorrect Answers
B:This predicts that the snippet prints '1', but executing the displayed Python 3 codeprints 'true'. A Python function without a reachable return statement returns the singleton None.
C:This predicts that the snippet prints 'false', but executing the displayed Python 3 codeprints 'true'. A Python function without a reachable return statement returns the singleton None.
D:This predicts that the snippet prints '0', but executing the displayed Python 3 codeprints 'true'. A Python function without a reachable return statement returns the singleton None.
Question 297
A learner is checking early return versus later statements. What is the exact printed result or uncaught exception?def f(x):
return x
x+=100
print(f(5))
- Prints '7'
- Prints '6'
- Prints '5'
- Prints '4'
Explanation
Correct Answer
C:The snippet prints '5'. Once a function returns, the remaining statements in that function call are not executed.
Incorrect Answers
A:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '5'. Once a function returns, the remaining statements in that function call are not executed.
B:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '5'. Once a function returns, the remaining statements in that function call are not executed.
D:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '5'. Once a function returns, the remaining statements in that function call are not executed.
Question 298
A developer tests early return versus later statements. The following code prints 'even'. Which explanation best accounts for that observed behavior?def f(n):
if n%2==0: return "even"
return "odd"
print(f(6))
- A recursive sum decreases the input until its base case and combines each return value on the way back.
- A default parameter supplies its predeclared value only when the call does not provide that argument.
- Once a function returns, the remaining statements in that function call are not executed.
- An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints 'even'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The recursive summation topic does not explain why the code prints 'even'. The relevant Python rule is: Once a function returns, the remaining statements in that function call are not executed.
B:The default parameter value used when omitted topic does not explain why the code prints 'even'. The relevant Python rule is: Once a function returns, the remaining statements in that function call are not executed.
D:The specific versus incorrect exception catch topic does not explain why the code prints 'even'. The relevant Python rule is: Once a function returns, the remaining statements in that function call are not executed.
Question 299
A learner is checking early return versus later statements. After this modification, what does Python 3 actually do?def f():
print("start")
return 2
print("end")
print(f())
- Prints '2\nstart'
- Prints 'start'
- Prints '2'
- Prints 'start\n2'
Explanation
Correct Answer
D:The snippet prints 'start\n2'. Once a function returns, the remaining statements in that function call are not executed.
Incorrect Answers
A:This predicts that the snippet prints '2\nstart', but executing the displayed Python 3 code prints 'start\n2'. Once a function returns, the remaining statements in that function call are not executed.
B:This predicts that the snippet prints 'start', but executing the displayed Python 3 code prints 'start\n2'. Once a function returns, the remaining statements in that function call are not executed.
C:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints 'start\n2'. Once a function returns, the remaining statements in that function call are not executed.
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.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests