100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 330
A developer tests mixed positional and keyword calls. The following code prints '123'. Which explanation best accounts for that observed behavior?def f(a,b,c): return 100*a+10*b+c
print(f(1,2,c=3))
- An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
- A global declaration makes assignment inside the function modify the module-level name.
- An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
- Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints '123'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The IndexError and KeyError distinct topic does not explain why the code prints '123'. The relevant Python rule is: Positional arguments may precede named arguments, but a single parameter cannot receive two values.
B:The global declaration changes module binding topic does not explain why the code prints '123'. The relevant Python rule is: Positional arguments may precede named arguments, but a single parameter cannot receive two values.
C:The nested try except responsibility topic does not explain why the code prints '123'. The relevant Python rule is: Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Question 331
A learner is checking mixed positional and keyword calls. After this modification, what does Python 3 actually do?def f(a,b): return a*b
print(f(a=2,3))
- Raises KeyError
- Raises SyntaxError
- Raises TypeError
- Raises IndexError
Explanation
Correct Answer
B:The snippet raises syntaxerror. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Incorrect Answers
A:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises syntaxerror. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
C:This predicts that the snippet raises typeerror, but executing the displayed Python 3 code raises syntaxerror. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
D:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises syntaxerror. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Question 332
During a review of mixed positional and keyword calls, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def f(a,b,c): return 100*a+10*b+c
print(f(1,2,c=3))
Program B:
def f(a,b): return a*b
print(f(a=2,3))
Program C:
def f(a,b): return a+b
print(f(1,a=2))
- Program B raises syntaxerror.
- Program A prints 'bad'.
- Program B prints '[0, 1, 4]'.
- Program C raises typeerror.
- Program C raises nameerror.
Explanation
Correct Answers
A:Running Program B raises syntaxerror. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
D:Running Program C raises typeerror. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Incorrect Answers
B:Program A does not produce 'bad'; its verified result is: Prints '123'. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
C:Program B does not produce '[0, 1, 4]'; its verified result is: Raises SyntaxError. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
E:Program C does not raises nameerror; its verified result is: Raises TypeError. Positional arguments may precede named arguments, but a single parameter cannot receive two values.
Question 333
A learner is checking default parameter value used when omitted. What is the exact printed result or uncaught exception?def greet(name="guest"): return "hi "+name
print(greet())
- Prints 'tseug ih'
- Prints 'hi gues'
- Prints 'hi guest'
- Prints 'hi guest?'
Explanation
Correct Answer
C:The snippet prints 'hi guest'. A default parameter supplies its predeclared value only when the call does not provide that argument.
Incorrect Answers
A:This predicts that the snippet prints 'tseug ih', but executing the displayed Python 3 code prints 'hi guest'. A default parameter supplies its predeclared value only when the call does not provide that argument.
B:This predicts that the snippet prints 'hi gues', but executing the displayed Python 3 code prints 'hi guest'. A default parameter supplies its predeclared value only when the call does not provide that argument.
D:This predicts that the snippet prints 'hi guest?', but executing the displayed Python 3 code prints 'hi guest'. A default parameter supplies its predeclared value only when the call does not provide that argument.
Question 334
A developer tests default parameter value used when omitted. The following code prints '9'. Which explanation best accounts for that observed behavior?def power(x,e=2): return x**e
print(power(3))
- An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
- An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
- A Python function without a reachable return statement returns the singleton None.
- A default parameter supplies its predeclared value only when the call does not provide that argument.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints '9'; 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 '9'. The relevant Python rule is: A default parameter supplies its predeclared value only when the call does not provide that argument.
B:The nested try except responsibility topic does not explain why the code prints '9'. The relevant Python rule is: A default parameter supplies its predeclared value only when the call does not provide that argument.
C:The implicit None return topic does not explain why the code prints '9'. The relevant Python rule is: A default parameter supplies its predeclared value only when the call does not provide that argument.
Question 335
A learner is checking default parameter value used when omitted. After this modification, what does Python 3 actually do?def add(a,b=4): return a+b
print(add(5,2))
- Prints '7'
- Prints '9'
- Prints '6'
- Prints '8'
Explanation
Correct Answer
A:The snippet prints '7'. A default parameter supplies its predeclared value only when the call does not provide that argument.
Incorrect Answers
B:This predicts that the snippet prints '9', but executing the displayed Python 3 code prints '7'. A default parameter supplies its predeclared value only when the call does not provide that argument.
C:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '7'. A default parameter supplies its predeclared value only when the call does not provide that argument.
D:This predicts that the snippet prints '8', but executing the displayed Python 3 code prints '7'. A default parameter supplies its predeclared value only when the call does not provide that argument.
Question 336
During a review of default parameter value used when omitted, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
def power(x,e=2): return x**e
print(power(3))
Program B:
def add(a,b=4): return a+b
print(add(5,2))
Program C:
def f(a=1,b=2): return a*10+b
print(f(b=5))
- Program A prints '1'.
- Program C prints '15'.
- Program C prints '24'.
- Program B prints '5'.
- Program B prints '7'.
Explanation
Correct Answers
B:Running Program C prints '15'. A default parameter supplies its predeclared value only when the call does not provide that argument.
E:Running Program B prints '7'. A default parameter supplies its predeclared value only when the call does not provide that argument.
Incorrect Answers
A:Program A does not produce '1'; its verified result is: Prints '9'. A default parameter supplies its predeclared value only when the call does not provide that argument.
C:Program C does not produce '24'; its verified result is: Prints '15'. A default parameter supplies its predeclared value only when the call does not provide that argument.
D:Program B does not produce '5'; its verified result is: Prints '7'. A default parameter supplies its predeclared value only when the call does not provide that argument.
Question 337
A learner is checking keyword can override positional default. What is the exact printed result or uncaught exception?def f(x=2): return x*3
print(f(x=5))
- Prints '15'
- Prints '16'
- Prints '17'
- Prints '14'
Explanation
Correct Answer
A:The snippet prints '15'. A supplied keyword value overrides a default parameter without changing the function definition.
Incorrect Answers
B:This predicts that the snippet prints '16', but executing the displayed Python 3 code prints '15'. A supplied keyword value overrides a default parameter without changing the function definition.
C:This predicts that the snippet prints '17', but executing the displayed Python 3 code prints '15'. A supplied keyword value overrides a default parameter without changing the function definition.
D:This predicts that the snippet prints '14', but executing the displayed Python 3 code prints '15'. A supplied keyword value overrides a default parameter without changing the function definition.
Question 338
A developer tests keyword can override positional default. The following code prints '5'. Which explanation best accounts for that observed behavior?def f(a,b=3): return a-b
print(f(9,b=4))
- Assigning to a parameter or local variable does not rebind the distinct global name without global.
- A supplied keyword value overrides a default parameter without changing the function definition.
- The except clause matching the raised exception class handles the error and allows execution to continue.
- 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 example prints '5'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The local name shadows global name topic does not explain why the code prints '5'. The relevant Python rule is: A supplied keyword value overrides a default parameter without changing the function definition.
C:The exact exception handler selection topic does not explain why the code prints '5'. The relevant Python rule is: A supplied keyword value overrides a default parameter without changing the function definition.
D:The exceptions propagate across function calls topic does not explain why the code prints '5'. The relevant Python rule is: A supplied keyword value overrides a default parameter without changing the function definition.
Question 339
A learner is checking keyword can override positional default. After this modification, what does Python 3 actually do?def f(x=10,y=1): return x+y
print(f(y=7))
- Prints '17'
- Prints '19'
- Prints '16'
- Prints '18'
Explanation
Correct Answer
A:The snippet prints '17'. A supplied keyword value overrides a default parameter without changing the function definition.
Incorrect Answers
B:This predicts that the snippet prints '19', but executing the displayed Python 3 code prints '17'. A supplied keyword value overrides a default parameter without changing the function definition.
C:This predicts that the snippet prints '16', but executing the displayed Python 3 code prints '17'. A supplied keyword value overrides a default parameter without changing the function definition.
D:This predicts that the snippet prints '18', but executing the displayed Python 3 code prints '17'. A supplied keyword value overrides a default parameter without changing the function definition.
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.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests