100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 390
A developer tests exceptions propagate across function calls. The following code prints 'bad'. Which explanation best accounts for that observed behavior?def g(): return int("no")
try: g()
except ValueError: print("bad")
- A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
- Once a function returns, the remaining statements in that function call are not executed.
- A global declaration makes assignment inside the function modify the module-level name.
- An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints 'bad'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The recursive factorial base case topic does not explain why the code prints 'bad'. The relevant Python rule is: An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
B:The early return versus later statements topic does not explain why the code prints 'bad'. The relevant Python rule is: An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
C:The global declaration changes module binding topic does not explain why the code prints 'bad'. The relevant Python rule is: An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Question 391
A learner is checking exceptions propagate across function calls. After this modification, what does Python 3 actually do?def f(): return [1][8]
try: f()
except KeyError: print("wrong")
- Raises IndexError
- Raises KeyError
- Raises ValueError
- Raises TypeError
Explanation
Correct Answer
A:The snippet raises indexerror. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Incorrect Answers
B:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises indexerror. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
C:This predicts that the snippet raises valueerror, but executing the displayed Python 3 code raises indexerror. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
D:This predicts that the snippet raises typeerror, but executing the displayed Python 3 code raises indexerror. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Question 392
During a review of exceptions propagate across function calls, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
def g(): return int("no")
try: g()
except ValueError: print("bad")
Program B:
def f(): return [1][8]
try: f()
except KeyError: print("wrong")
Program C:
def f(): return 8//2
try: print(f())
except ZeroDivisionError: print("error")
- Program B raises indexerror.
- Program A prints 'bad'.
- Program C prints '3'.
- Program A prints '[1]'.
- Program B raises valueerror.
- Program C prints '4'.
Explanation
Correct Answers
A:Running Program B raises indexerror. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
B:Running Program A prints 'bad'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
F:Running Program C prints '4'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Incorrect Answers
C:Program C does not produce '3'; its verified result is: Prints '4'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
D:Program A does not produce '[1]'; its verified result is: Prints 'bad'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
E:Program B does not raises valueerror; its verified result is: Raises IndexError. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Question 393
A learner is checking specific versus incorrect exception catch. What is the exact printed result or uncaught exception?try: print(4/0)
except ValueError: print("value")
- Raises ZeroDivisionError
- Raises TypeError
- Raises IndexError
- Raises KeyError
Explanation
Correct Answer
A:The snippet raises zerodivisionerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Incorrect Answers
B:This predicts that the snippet raises typeerror, but executing the displayed Python 3 code raises zerodivisionerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
C:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises zerodivisionerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
D:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises zerodivisionerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Question 394
A developer tests specific versus incorrect exception catch. The following code raises keyerror. Which explanation best accounts for that observed behavior?try: print({}["x"])
except IndexError: print("index")
- An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
- An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
- The result returned by one function can be passed directly as an argument to another function.
- 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 raises keyerror; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The IndexError and KeyError distinct topic does not explain why the code raises keyerror. The relevant Python rule is: An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
C:The function call composition topic does not explain why the code raises keyerror. The relevant Python rule is: An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
D:The ValueError versus TypeError in conversion topic does not explain why the code raises keyerror. The relevant Python rule is: An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Question 395
A learner is checking specific versus incorrect exception catch. After this modification, what does Python 3 actually do?try: print(int("q"))
except TypeError: print("type")
- Raises TypeError
- Raises KeyError
- Raises IndexError
- Raises ValueError
Explanation
Correct Answer
D:The snippet raises valueerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Incorrect Answers
A:This predicts that the snippet raises typeerror, but executing the displayed Python 3 code raises valueerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
B:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises valueerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
C:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises valueerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Question 396
During a review of specific versus incorrect exception catch, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
try: print({}["x"])
except IndexError: print("index")
Program B:
try: print(int("q"))
except TypeError: print("type")
Program C:
try: print([1][4])
except LookupError: print("lookup")
- Program C prints '(1, 2)'.
- Program A prints 'lookup'.
- Program A raises keyerror.
- Program B raises valueerror.
- Program C prints 'lookup'.
- Program B prints 'hi\nnone'.
Explanation
Correct Answers
C:Running Program A raises keyerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
D:Running Program B raises valueerror. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
E:Running Program C prints 'lookup'. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Incorrect Answers
A:Program C does not produce '(1, 2)'; its verified result is: Prints 'lookup'. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
B:Program A does not produce 'lookup'; its verified result is: Raises KeyError. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
F:Program B does not produce 'hi\nnone'; its verified result is: Raises ValueError. An except block for an unrelated exception does not intercept the error and execution fails at the uncaught exception.
Question 397
A learner is checking nested try except responsibility. What is the exact printed result or uncaught exception?try:
try: int("no")
except ValueError: print("inner")
except Exception: print("outer")
- Prints 'renni'
- Prints 'inner'
- Prints 'inne'
- Prints 'inner?'
Explanation
Correct Answer
B:The snippet prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
Incorrect Answers
A:This predicts that the snippet prints 'renni', but executing the displayed Python 3 code prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
C:This predicts that the snippet prints 'inne', but executing the displayed Python 3 code prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
D:This predicts that the snippet prints 'inner?', but executing the displayed Python 3 code prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
Question 398
A developer tests nested try except responsibility. The following code prints 'outer'. Which explanation best accounts for that observed behavior?try:
try: print(1/0)
except ValueError: print("inner")
except ZeroDivisionError: print("outer")
- An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
- The result returned by one function can be passed directly as an argument to another function.
- Positional arguments may precede named arguments, but a single parameter cannot receive two values.
- 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 'outer'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The function call composition topic does not explain why the code prints 'outer'. The relevant Python rule is: An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
C:The mixed positional and keyword calls topic does not explain why the code prints 'outer'. The relevant Python rule is: An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
D:The ValueError versus TypeError in conversion topic does not explain why the code prints 'outer'. The relevant Python rule is: An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
Question 399
A learner is checking nested try except responsibility. After this modification, what does Python 3 actually do?try:
try: print([1][5])
except IndexError: print("inner")
except LookupError: print("outer")
- Prints 'inner?'
- Prints 'inne'
- Prints 'inner'
- Prints 'renni'
Explanation
Correct Answer
C:The snippet prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
Incorrect Answers
A:This predicts that the snippet prints 'inner?', but executing the displayed Python 3 code prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
B:This predicts that the snippet prints 'inne', but executing the displayed Python 3 code prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
D:This predicts that the snippet prints 'renni', but executing the displayed Python 3 code prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
Question 400
During a review of nested try except responsibility, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
try:
try: print(1/0)
except ValueError: print("inner")
except ZeroDivisionError: print("outer")
Program B:
try:
try: print([1][5])
except IndexError: print("inner")
except LookupError: print("outer")
Program C:
try:
try: print({}["x"])
except TypeError: print("inner")
except KeyError: print("outer")
- Program B prints 'inner'.
- Program A prints 'outer'.
- Program C prints 'outer'.
- Program B prints 'broad'.
- Program A prints 'false'.
- Program C prints 'other'.
Explanation
Correct Answers
A:Running Program B prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
B:Running Program A prints 'outer'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
C:Running Program C prints 'outer'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
Incorrect Answers
D:Program B does not produce 'broad'; its verified result is: Prints 'inner'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
E:Program A does not produce 'false'; its verified result is: Prints 'outer'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
F:Program C does not produce 'other'; its verified result is: Prints 'outer'. An inner try-except handles matching exceptions; otherwise an outer compatible handler can receive the propagated error.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests