100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 380
During a review of IndexError and KeyError distinct, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
print({"x":1}["y"])
Program B:
print([5,6][-1])
Program C:
print({"a":9}["a"])
- Program B prints '5'.
- Program A prints '[1, 7]'.
- Program B prints '6'.
- Program C prints '9'.
- Program C prints '2'.
- Program A raises keyerror.
Explanation
Correct Answers
C:Running Program B prints '6'. An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
D:Running Program C prints '9'. An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
F:Running Program A raises keyerror. An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
Incorrect Answers
A:Program B does not produce '5'; its verified result is: Prints '6'. An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
B:Program A does not produce '[1, 7]'; its verified result is: Raises KeyError. An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
E:Program C does not produce '2'; its verified result is: Prints '9'. An absent list index produces IndexError whereas a missing dictionary key produces KeyError.
Question 381
A learner is checking exact exception handler selection. What is the exact printed result or uncaught exception?try:
n=1/0
except ZeroDivisionError:
print("caught")
- Prints 'caugh'
- Prints 'caught'
- Prints 'thguac'
- Prints 'caught?'
Explanation
Correct Answer
B:The snippet prints 'caught'. The except clause matching the raised exception class handles the error and allows execution to continue.
Incorrect Answers
A:This predicts that the snippet prints 'caugh', but executing the displayed Python 3 code prints 'caught'. The except clause matching the raised exception class handles the error and allows execution to continue.
C:This predicts that the snippet prints 'thguac', but executing the displayed Python 3 code prints 'caught'. The except clause matching the raised exception class handles the error and allows execution to continue.
D:This predicts that the snippet prints 'caught?', but executing the displayed Python 3 code prints 'caught'. The except clause matching the raised exception class handles the error and allows execution to continue.
Question 382
A developer tests exact exception handler selection. The following code prints 'bad integer'. Which explanation best accounts for that observed behavior?try:
x=int("oops")
except ValueError:
print("bad integer")
- The except clause matching the raised exception class handles the error and allows execution to continue.
- Providing a parameter both positionally and by keyword causes TypeError for multiple values.
- The result returned by one function can be passed directly as an argument to another function.
- KeyboardInterrupt and SystemExit derive from BaseException but not from the Exception subclass.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints 'bad integer'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The duplicate argument assignment raises TypeError topic does not explain why the code prints 'bad integer'. The relevant Python rule is: The except clause matching the raised exception class handles the error and allows execution to continue.
C:The function call composition topic does not explain why the code prints 'bad integer'. The relevant Python rule is: The except clause matching the raised exception class handles the error and allows execution to continue.
D:The BaseException versus Exception topic does not explain why the code prints 'bad integer'. The relevant Python rule is: The except clause matching the raised exception class handles the error and allows execution to continue.
Question 383
A learner is checking exact exception handler selection. After this modification, what does Python 3 actually do?try:
print([1][9])
except IndexError:
print("index")
- Prints 'index'
- Prints 'inde'
- Prints 'index?'
- Prints 'xedni'
Explanation
Correct Answer
A:The snippet prints 'index'. The except clause matching the raised exception class handles the error and allows execution to continue.
Incorrect Answers
B:This predicts that the snippet prints 'inde', but executing the displayed Python 3 code prints 'index'. The except clause matching the raised exception class handles the error and allows execution to continue.
C:This predicts that the snippet prints 'index?', but executing the displayed Python 3 code prints 'index'. The except clause matching the raised exception class handles the error and allows execution to continue.
D:This predicts that the snippet prints 'xedni', but executing the displayed Python 3 code prints 'index'. The except clause matching the raised exception class handles the error and allows execution to continue.
Question 384
During a review of exact exception handler selection, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
try:
x=int("oops")
except ValueError:
print("bad integer")
Program B:
try:
print([1][9])
except IndexError:
print("index")
Program C:
try:
print(3+"4")
except TypeError:
print("types")
- Program A prints 'bad integer'.
- Program A raises stopiteration.
- Program B prints 'broad'.
- Program B prints 'index'.
- Program C prints 'types'.
- Program C prints 'index'.
Explanation
Correct Answers
A:Running Program A prints 'bad integer'. The except clause matching the raised exception class handles the error and allows execution to continue.
D:Running Program B prints 'index'. The except clause matching the raised exception class handles the error and allows execution to continue.
E:Running Program C prints 'types'. The except clause matching the raised exception class handles the error and allows execution to continue.
Incorrect Answers
B:Program A does not raises stopiteration; its verified result is: Prints 'bad integer'. The except clause matching the raised exception class handles the error and allows execution to continue.
C:Program B does not produce 'broad'; its verified result is: Prints 'index'. The except clause matching the raised exception class handles the error and allows execution to continue.
F:Program C does not produce 'index'; its verified result is: Prints 'types'. The except clause matching the raised exception class handles the error and allows execution to continue.
Question 385
A learner is checking first matching except branch. What is the exact printed result or uncaught exception?try:
int("no")
except Exception:
print("broad")
except ValueError:
print("narrow")
- Prints 'broad?'
- Prints 'broa'
- Prints 'broad'
- Prints 'daorb'
Explanation
Correct Answer
C:The snippet prints 'broad'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
Incorrect Answers
A:This predicts that the snippet prints 'broad?', but executing the displayed Python 3 code prints 'broad'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
B:This predicts that the snippet prints 'broa', but executing the displayed Python 3 code prints 'broad'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
D:This predicts that the snippet prints 'daorb', but executing the displayed Python 3 code prints 'broad'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
Question 386
A developer tests first matching except branch. The following code prints 'specific'. Which explanation best accounts for that observed behavior?try:
1/0
except ZeroDivisionError:
print("specific")
except Exception:
print("general")
- A global declaration makes assignment inside the function modify the module-level name.
- A recursive function must reach a base case; factorial multiplies n by factorial(n-1) until n<=1.
- Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
- KeyboardInterrupt and SystemExit derive from BaseException but not from the Exception subclass.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints 'specific'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The global declaration changes module binding topic does not explain why the code prints 'specific'. The relevant Python rule is: Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
B:The recursive factorial base case topic does not explain why the code prints 'specific'. The relevant Python rule is: Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
D:The BaseException versus Exception topic does not explain why the code prints 'specific'. The relevant Python rule is: Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
Question 387
A learner is checking first matching except branch. After this modification, what does Python 3 actually do?try:
[][0]
except LookupError:
print("lookup")
except IndexError:
print("index")
- Prints 'lookup?'
- Prints 'looku'
- Prints 'lookup'
- Prints 'pukool'
Explanation
Correct Answer
C:The snippet prints 'lookup'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
Incorrect Answers
A:This predicts that the snippet prints 'lookup?', but executing the displayed Python 3 code prints 'lookup'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
B:This predicts that the snippet prints 'looku', but executing the displayed Python 3 code prints 'lookup'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
D:This predicts that the snippet prints 'pukool', but executing the displayed Python 3 code prints 'lookup'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
Question 388
During a review of first matching except branch, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
try:
1/0
except ZeroDivisionError:
print("specific")
except Exception:
print("general")
Program B:
try:
[][0]
except LookupError:
print("lookup")
except IndexError:
print("index")
Program C:
try:
{}["missing"]
except KeyError:
print("key")
except Exception:
print("other")
- Program C prints 'key'.
- Program B prints 'lookup'.
- Program C prints 'xxx'.
- Program B prints '(1, 2)'.
- Program A prints 'hi guest'.
- Program A prints 'specific'.
Explanation
Correct Answers
A:Running Program C prints 'key'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
B:Running Program B prints 'lookup'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
F:Running Program A prints 'specific'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
Incorrect Answers
C:Program C does not produce 'xxx'; its verified result is: Prints 'key'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
D:Program B does not produce '(1, 2)'; its verified result is: Prints 'lookup'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
E:Program A does not produce 'hi guest'; its verified result is: Prints 'specific'. Exception handlers are checked in order; a broad superclass handler before a specific one makes the later one unreachable.
Question 389
A learner is checking exceptions propagate across function calls. What is the exact printed result or uncaught exception?def f(): return 1/0
try: print(f())
except ZeroDivisionError: print("handled")
- Prints 'handle'
- Prints 'deldnah'
- Prints 'handled'
- Prints 'handled?'
Explanation
Correct Answer
C:The snippet prints 'handled'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
Incorrect Answers
A:This predicts that the snippet prints 'handle', but executing the displayed Python 3 code prints 'handled'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
B:This predicts that the snippet prints 'deldnah', but executing the displayed Python 3 code prints 'handled'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
D:This predicts that the snippet prints 'handled?', but executing the displayed Python 3 code prints 'handled'. An uncaught exception raised inside a function propagates to the caller where a matching except can catch it.
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.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests