Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A payroll script calls `calculate_bonus(employee_id, base)` inside a try block. The function raises a custom exception `BonusError` when the employee is not eligible, and the script wants to log that specific failure while still letting an unexpected ZeroDivisionError propagate to a global handler. Which except clause should the developer write?

⚠ Common exam trap

The trap here is believing that writing two exception class names separated by a comma or the word or catches both, when Python 3 requires a parenthesized tuple and evaluates or to a single class.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

except BonusError as err:

Naming a single specific exception type in an except clause handles exactly that failure and lets everything else propagate. Binding it with as captures the instance for logging without broadening the catch. Catching a base class or listing unrelated types would either swallow unexpected errors or fail syntactically, defeating the script's escalation requirement.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    except BonusError or ZeroDivisionError as err:

    Why it's wrong here

    Python evaluates `BonusError or ZeroDivisionError` to the first truthy class object, which is BonusError, so this clause behaves like catching only BonusError and is misleading. To catch multiple types the correct syntax is a tuple: except (BonusError, ZeroDivisionError). The written form would also fail to catch ZeroDivisionError as apparently intended.

  • ✗

    except BonusError, ZeroDivisionError as err:

    Why it's wrong here

    Python 3 removed the comma-separated except syntax; this line is a syntax error and the script would not even parse. Multiple exception types must be written as a parenthesized tuple. Beyond the syntax problem, catching ZeroDivisionError here would contradict the requirement to let unexpected arithmetic errors reach the global handler.

  • ✓

    except BonusError as err:

    Why this is correct

    Catching the specific exception type handles only the anticipated ineligibility case and binds the exception instance to err for logging. Any other exception, such as ZeroDivisionError, does not match this clause and therefore propagates to the outer handler. This selective approach gives precise control over which failures are swallowed and which are escalated.

  • ✗

    except Exception as err:

    Why it's wrong here

    The Exception base class matches nearly every ordinary runtime error, including ZeroDivisionError, so the unexpected division failure would be caught and logged as a bonus issue instead of reaching the global handler. This over-broad clause hides genuine bugs and violates the requirement that only the specific eligibility failure be handled locally.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.