100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 340
During a review of keyword can override positional default, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def f(a,b=3): return a-b
print(f(9,b=4))
Program B:
def f(x=10,y=1): return x+y
print(f(y=7))
Program C:
def f(prefix="x",num=2): return prefix*num
print(f(num=3))
- Program C prints 'bad'.
- Program A prints '7'.
- Program C prints 'xxx'.
- Program B prints '17'.
- Program B prints 'ab'.
Explanation
Correct Answers
C:Running Program C prints 'xxx'. A supplied keyword value overrides a default parameter without changing the function definition.
D:Running Program B prints '17'. A supplied keyword value overrides a default parameter without changing the function definition.
Incorrect Answers
A:Program C does not produce 'bad'; its verified result is: Prints 'xxx'. A supplied keyword value overrides a default parameter without changing the function definition.
B:Program A does not produce '7'; its verified result is: Prints '5'. A supplied keyword value overrides a default parameter without changing the function definition.
E:Program B does not produce 'ab'; its verified result is: Prints '17'. A supplied keyword value overrides a default parameter without changing the function definition.
Question 341
A learner is checking local name shadows global name. What is the exact printed result or uncaught exception?x=9
def f(x):
x+=1
return x
print(f(2),x)
- Prints '3 9?'
- Prints '3 9'
- Prints '9 3'
- Prints '3 '
Explanation
Correct Answer
B:The snippet prints '3 9'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
Incorrect Answers
A:This predicts that the snippet prints '3 9?', but executing the displayed Python 3 code prints '3 9'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
C:This predicts that the snippet prints '9 3', but executing the displayed Python 3 code prints '3 9'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
D:This predicts that the snippet prints '3 ', but executing the displayed Python 3 code prints '3 9'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
Question 342
A developer tests local name shadows global name. The following code prints '7 4'. Which explanation best accounts for that observed behavior?value=4
def f():
value=7
return value
print(f(),value)
- The except clause matching the raised exception class handles the error and allows execution to continue.
- Assigning to a parameter or local variable does not rebind the distinct global name without global.
- A default parameter supplies its predeclared value only when the call does not provide that argument.
- A global declaration makes assignment inside the function modify the module-level name.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '7 4'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The exact exception handler selection topic does not explain why the code prints '7 4'. The relevant Python rule is: Assigning to a parameter or local variable does not rebind the distinct global name without global.
C:The default parameter value used when omitted topic does not explain why the code prints '7 4'. The relevant Python rule is: Assigning to a parameter or local variable does not rebind the distinct global name without global.
D:The global declaration changes module binding topic does not explain why the code prints '7 4'. The relevant Python rule is: Assigning to a parameter or local variable does not rebind the distinct global name without global.
Question 343
A learner is checking local name shadows global name. After this modification, what does Python 3 actually do?x=5
def f(x): return x*2
print(f(3),x)
- Prints '6 '
- Prints '6 5?'
- Prints '6 5'
- Prints '5 6'
Explanation
Correct Answer
C:The snippet prints '6 5'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
Incorrect Answers
A:This predicts that the snippet prints '6 ', but executing the displayed Python 3 code prints '6 5'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
B:This predicts that the snippet prints '6 5?', but executing the displayed Python 3 code prints '6 5'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
D:This predicts that the snippet prints '5 6', but executing the displayed Python 3 code prints '6 5'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
Question 344
During a review of local name shadows global name, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
value=4
def f():
value=7
return value
print(f(),value)
Program B:
x=5
def f(x): return x*2
print(f(3),x)
Program C:
n=3
def f():
n=10
return n-1
print(n,f())
- Program C prints '1 2'.
- Program A prints '1 2'.
- Program B prints '6 5'.
- Program B prints '7 4'.
- Program C prints '3 9'.
Explanation
Correct Answers
C:Running Program B prints '6 5'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
E:Running Program C prints '3 9'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
Incorrect Answers
A:Program C does not produce '1 2'; its verified result is: Prints '3 9'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
B:Program A does not produce '1 2'; its verified result is: Prints '7 4'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
D:Program B does not produce '7 4'; its verified result is: Prints '6 5'. Assigning to a parameter or local variable does not rebind the distinct global name without global.
Question 345
A learner is checking global declaration changes module binding. What is the exact printed result or uncaught exception?n=2
def f():
global n
n+=3
f()
print(n)
- Prints '7'
- Prints '5'
- Prints '6'
- Prints '4'
Explanation
Correct Answer
B:The snippet prints '5'. A global declaration makes assignment inside the function modify the module-level name.
Incorrect Answers
A:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '5'. A global declaration makes assignment inside the function modify the module-level name.
C:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '5'. A global declaration makes assignment inside the function modify the module-level name.
D:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '5'. A global declaration makes assignment inside the function modify the module-level name.
Question 346
A developer tests global declaration changes module binding. The following code prints 'true'. Which explanation best accounts for that observed behavior?flag=False
def on():
global flag
flag=True
on()
print(flag)
- Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
- A global declaration makes assignment inside the function modify the module-level name.
- Positional arguments may precede named arguments, but a single parameter cannot receive two values.
- An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the exampleprints 'true'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:That statement describes the separate topic first matching except branch. It does not account for this example, whose result isprints 'true'. The relevant rule is: A global declaration makes assignment inside the function modify the module-level name.
C:That statement describes the separate topic mixed positional and keyword calls. It does not account for this example, whose result isprints 'true'. The relevant rule is: A global declaration makes assignment inside the function modify the module-level name.
D:That statement describes the separate topic exceptions propagate across function calls. It does not account for this example, whose result isprints 'true'. The relevant rule is: A global declaration makes assignment inside the function modify the module-level name.
Question 347
A learner is checking global declaration changes module binding. After this modification, what does Python 3 actually do?x=1
def f():
global x
x=x*4
f()
print(x)
- Prints '4'
- Prints '5'
- Prints '6'
- Prints '3'
Explanation
Correct Answer
A:The snippet prints '4'. A global declaration makes assignment inside the function modify the module-level name.
Incorrect Answers
B:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '4'. A global declaration makes assignment inside the function modify the module-level name.
C:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '4'. A global declaration makes assignment inside the function modify the module-level name.
D:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '4'. A global declaration makes assignment inside the function modify the module-level name.
Question 348
During a review of global declaration changes module binding, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
flag=False
def on():
global flag
flag=True
on()
print(flag)
Program B:
x=1
def f():
global x
x=x*4
f()
print(x)
Program C:
text="a"
def f():
global text
text+="b"
f()
print(text)
- Program B prints '9'.
- Program C prints '12'.
- Program A prints 'even'.
- Program B prints '4'.
- Program C prints 'ab'.
Explanation
Correct Answers
D:Running Program B prints '4'. A global declaration makes assignment inside the function modify the module-level name.
E:Running Program C prints 'ab'. A global declaration makes assignment inside the function modify the module-level name.
Incorrect Answers
A:Program B does not produce '9'; its verified result is: Prints '4'. A global declaration makes assignment inside the function modify the module-level name.
B:Program C does not produce '12'; its verified result is: Prints 'ab'. A global declaration makes assignment inside the function modify the module-level name.
C:Program A does not produce 'even'; its verified result is:prints 'True'. A global declaration makes assignment inside the function modify the module-level name.
Question 349
A learner is checking local variable before assignment error. What is the exact printed result or uncaught exception?x=5
def f():
print(x)
x=6
f()
- Raises UnboundLocalError
- Raises IndexError
- Raises TypeError
- Raises KeyError
Explanation
Correct Answer
A:The snippet raises unboundlocalerror. 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 raises indexerror, but executing the displayed Python 3 code raises unboundlocalerror. 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 raises typeerror, but executing the displayed Python 3 code raises unboundlocalerror. 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 raises keyerror, but executing the displayed Python 3 code raises unboundlocalerror. Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
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.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests