Courseiva
Functions, Tuples, Dictionaries and ExceptionseasyMultiple ChoiceObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

What does the following code output?

try:

x = int('abc') except ValueError:

print('Invalid')

⚠ Common exam trap

The PCEP exam often tests whether candidates understand that a caught exception does not crash the program; the trap here is that some candidates think any error causes a crash, but the except block prevents that.

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

Invalid

The code attempts to convert the string 'abc' to an integer using int(). Since 'abc' is not a valid integer, Python raises a ValueError. The except block catches this specific exception and executes print('Invalid'), so the output is 'Invalid'. Option B is correct because the exception is handled gracefully without crashing.

Answer analysis

Option-by-option breakdown

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

  • The program crashes

    Why it's wrong here

    The exception is caught, so no crash.

  • Invalid

    Why this is correct

    The ValueError is raised and caught, printing 'Invalid'.

  • (Nothing printed)

    Why it's wrong here

    An exception occurs, so the except block executes.

  • abc

    Why it's wrong here

    No print statement for the value.

About these practice questions

One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.