Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

Exhibit

Refer to the exhibit.

def divide(a, b):
    try:
        result = a / b
        print('Result:', result)
    except ZeroDivisionError:
        print('Cannot divide by zero')
    except TypeError:
        print('Unsupported operand')

divide(10, 0)

What is the output when the following code is executed?

try:
    print(1/0)

except ZeroDivisionError:

print("Cannot divide by zero")

⚠ Common exam trap

Python Institute often tests the distinction between an unhandled exception (crash) and a caught exception (graceful handling). In this case, the exception is caught, so the program does not crash.

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

✓

Cannot divide by zero

The code inside the try block attempts to divide by zero, which raises a ZeroDivisionError. The except block catches this exception and executes its print statement, outputting 'Cannot divide by zero'.

Answer analysis

Option-by-option breakdown

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

  • ✓

    Cannot divide by zero

    Why this is correct

    Dividing 1 by 0 raises a ZeroDivisionError, which the except clause catches by matching that exact exception type. The handler then executes its print statement, emitting the string "Cannot divide by zero" instead of terminating with a traceback. This satisfies the stem's requirement to show the caught-exception output.

  • ✗

    The program crashes with an unhandled exception

    Why it's wrong here

    ZeroDivisionError is caught by the except block, so the handler prints the message and execution continues normally; no traceback is raised. An unhandled crash would occur only if the division sat outside a matching except clause.

  • ✗

    Result: 0

    Why it's wrong here

    ZeroDivisionError is raised by 1/0, so the except block runs and prints its message; no arithmetic result is ever produced. The value 0 tempts because dividing zero by something yields zero, but here the divisor is zero, which Python forbids outright.

  • ✗

    Unsupported operand

    Why it's wrong here

    Python raises ZeroDivisionError for integer division by zero, and the except clause catches it, printing the message rather than an operand error. "Unsupported operand" tempts because TypeError arises from mismatched types, not from dividing by zero.

About these practice questions

This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.