Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

What is the output of the following code? try: print(1/0); except ZeroDivisionError: print('error'); finally: print('done')

⚠ Common exam trap

The PCEP exam often tests the mandatory execution order of the finally block, tricking candidates into thinking it only runs when no exception occurs or that it runs before the except block.

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

✓

error done

The code attempts to divide 1 by 0, which raises a ZeroDivisionError. The except block catches this specific exception and prints 'error', then the finally block always executes, printing 'done'. The output is therefore 'error' followed by 'done' on separate lines.

Answer analysis

Option-by-option breakdown

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

  • ✓

    error done

    Why this is correct

    Dividing by zero raises ZeroDivisionError, caught by the except block, which prints 'error'. The finally block always executes regardless of exception handling, printing 'done'. This satisfies the stem's requirement to show both the handled exception output and the guaranteed finally output.

  • ✗

    error

    Why it's wrong here

    The finally block always executes, so 'done' prints after 'error', making the complete output two lines. 'error' alone omits that trailing line. It is tempting because the except clause does print 'error', and that would be the entire output if no finally block were present.

  • ✗

    done error

    Why it's wrong here

    The order is reversed: the except block runs first, printing 'error', then finally prints 'done'. The finally clause executes after exception handling, not before, so 'done' cannot precede 'error'. This ordering would only occur if finally were written above the except clause.

  • ✗

    1/0 done

    Why it's wrong here

    The ZeroDivisionError is caught, so 'error' prints instead of the expression text, and finally prints 'done' rather than the literal '1/0'. Printing '1/0' would require the division to succeed and output that string, which never happens here.

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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.