100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 350
A developer tests local variable before assignment error. The following code raises unboundlocalerror. Which explanation best accounts for that observed behavior?n=3
def f():
n=n+1
return n
print(f())
- A generator yields values lazily and resumes after each yield when next is called.
- Keyword arguments bind by parameter name regardless of the order in which keywords are written.
- Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
- 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 raises unboundlocalerror; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The generator yield suspends state topic does not explain why the code raises unboundlocalerror. The relevant Python rule is: Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
B:The keyword argument binding topic does not explain why the code raises unboundlocalerror. The relevant Python rule is: Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
D:The mutable list argument shared with caller topic does not explain why the code raises unboundlocalerror. The relevant Python rule is: Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
Question 351
A learner is checking local variable before assignment error. After this modification, what does Python 3 actually do?x=2
def f():
global x
x=x+4
f()
print(x)
- Prints '6'
- Prints '8'
- Prints '7'
- Prints '5'
Explanation
Correct Answer
A:The snippet prints '6'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
Incorrect Answers
B:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '6'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
C:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '6'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
D:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '6'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
Question 352
During a review of local variable before assignment error, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
n=3
def f():
n=n+1
return n
print(f())
Program B:
x=2
def f():
global x
x=x+4
f()
print(x)
Program C:
x=10
def f():
return x
print(f())
- Program B prints '6'.
- Program B prints '3'.
- Program C prints '10'.
- Program A raises zerodivisionerror.
- Program C prints '16'.
Explanation
Correct Answers
A:Running Program B prints '6'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
C:Running Program C prints '10'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
Incorrect Answers
B:Program B does not produce '3'; its verified result is: Prints '6'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
D:Program A does not raises zerodivisionerror; its verified result is: Raises UnboundLocalError. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
E:Program C does not produce '16'; its verified result is: Prints '10'. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
Question 353
A learner is checking mutable list argument shared with caller. What is the exact printed result or uncaught exception?def add(a): a.append(7)
items=[1]
add(items)
print(items)
- Prints '[1]'
- Prints '[1, 7]'
- Prints '[7]'
- Prints '[7, 1]'
Explanation
Correct Answer
B:The snippet prints '[1, 7]'. A function modifying a list argument in place changes the same list observed by its caller.
Incorrect Answers
A:This predicts that the snippet prints '[1]', but executing the displayed Python 3 code prints '[1, 7]'. A function modifying a list argument in place changes the same list observed by its caller.
C:This predicts that the snippet prints '[7]', but executing the displayed Python 3 code prints '[1, 7]'. A function modifying a list argument in place changes the same list observed by its caller.
D:This predicts that the snippet prints '[7, 1]', but executing the displayed Python 3 code prints '[1, 7]'. A function modifying a list argument in place changes the same list observed by its caller.
Question 354
A developer tests mutable list argument shared with caller. The following code prints '[9, 2]'. Which explanation best accounts for that observed behavior?def f(a): a[0]=9
v=[1,2]
f(v)
print(v)
- A Python function without a reachable return statement returns the singleton None.
- Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
- A function modifying a list argument in place changes the same list observed by its caller.
- 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 '[9, 2]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The implicit None return topic does not explain why the code prints '[9, 2]'. The relevant Python rule is: A function modifying a list argument in place changes the same list observed by its caller.
B:The first matching except branch topic does not explain why the code prints '[9, 2]'. The relevant Python rule is: A function modifying a list argument in place changes the same list observed by its caller.
D:The specific versus incorrect exception catch topic does not explain why the code prints '[9, 2]'. The relevant Python rule is: A function modifying a list argument in place changes the same list observed by its caller.
Question 355
A learner is checking mutable list argument shared with caller. After this modification, what does Python 3 actually do?def f(a): a=a+[3]
v=[1]
f(v)
print(v)
- Prints '[1, 0]'
- Prints '[]'
- Prints '[1]'
- Prints '[2]'
Explanation
Correct Answer
C:The snippet prints '[1]'. A function modifying a list argument in place changes the same list observed by its caller.
Incorrect Answers
A:This predicts that the snippet prints '[1, 0]', but executing the displayed Python 3 code prints '[1]'. A function modifying a list argument in place changes the same list observed by its caller.
B:This predicts that the snippet prints '[]', but executing the displayed Python 3 code prints '[1]'. A function modifying a list argument in place changes the same list observed by its caller.
D:This predicts that the snippet prints '[2]', but executing the displayed Python 3 code prints '[1]'. A function modifying a list argument in place changes the same list observed by its caller.
Question 356
During a review of mutable list argument shared with caller, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def f(a): a[0]=9
v=[1,2]
f(v)
print(v)
Program B:
def f(a): a=a+[3]
v=[1]
f(v)
print(v)
Program C:
def f(a): a.extend([2,3])
v=[]
f(v)
print(v)
- Program A prints 'caught'.
- Program B prints '[1]'.
- Program C prints 'lookup'.
- Program B prints '2 5'.
- Program C prints '[2, 3]'.
Explanation
Correct Answers
B:Running Program B prints '[1]'. A function modifying a list argument in place changes the same list observed by its caller.
E:Running Program C prints '[2, 3]'. A function modifying a list argument in place changes the same list observed by its caller.
Incorrect Answers
A:Program A does not produce 'caught'; its verified result is: Prints '[9, 2]'. A function modifying a list argument in place changes the same list observed by its caller.
C:Program C does not produce 'lookup'; its verified result is: Prints '[2, 3]'. A function modifying a list argument in place changes the same list observed by its caller.
D:Program B does not produce '2 5'; its verified result is: Prints '[1]'. A function modifying a list argument in place changes the same list observed by its caller.
Question 357
A learner is checking duplicate argument assignment raises TypeError. What is the exact printed result or uncaught exception?def f(x): return x
print(f(1,x=2))
- Raises KeyError
- Raises IndexError
- Raises TypeError
- Raises ValueError
Explanation
Correct Answer
C:The snippet raises typeerror. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
Incorrect Answers
A:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises typeerror. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
B:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises typeerror. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
D:This predicts that the snippet raises valueerror, but executing the displayed Python 3 code raises typeerror. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
Question 358
A developer tests duplicate argument assignment raises TypeError. The following code raises typeerror. Which explanation best accounts for that observed behavior?def f(a,b): return a+b
print(f(1,a=2,b=3))
- Providing a parameter both positionally and by keyword causes TypeError for multiple values.
- A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
- 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.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example raises typeerror; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The recursive factorial base case topic does not explain why the code raises typeerror. The relevant Python rule is: Providing a parameter both positionally and by keyword causes TypeError for multiple values.
C:The recursive summation topic does not explain why the code raises typeerror. The relevant Python rule is: Providing a parameter both positionally and by keyword causes TypeError for multiple values.
D:The first matching except branch topic does not explain why the code raises typeerror. The relevant Python rule is: Providing a parameter both positionally and by keyword causes TypeError for multiple values.
Question 359
A learner is checking duplicate argument assignment raises TypeError. After this modification, what does Python 3 actually do?def f(x,y): return x+y
print(f(1,y=2))
- Prints '4'
- Prints '3'
- Prints '5'
- Prints '2'
Explanation
Correct Answer
B:The snippet prints '3'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
Incorrect Answers
A:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '3'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
C:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '3'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
D:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints '3'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
Question 360
During a review of duplicate argument assignment raises TypeError, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
def f(a,b): return a+b
print(f(1,a=2,b=3))
Program B:
def f(x,y): return x+y
print(f(1,y=2))
Program C:
def f(x=1): return x
print(f(x=4))
- Program B prints '3'.
- Program A raises typeerror.
- Program A raises nameerror.
- Program C prints '4'.
- Program C prints '8'.
- Program B prints '6'.
Explanation
Correct Answers
A:Running Program B prints '3'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
B:Running Program A raises typeerror. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
D:Running Program C prints '4'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
Incorrect Answers
C:Program A does not raises nameerror; its verified result is: Raises TypeError. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
E:Program C does not produce '8'; its verified result is: Prints '4'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
F:Program B does not produce '6'; its verified result is: Prints '3'. Providing a parameter both positionally and by keyword causes TypeError for multiple values.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests