Courseiva
Computer Programming and Python FundamentalseasyMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

Exhibit

try:
    x = int("hello")
except ValueError:
    print("Invalid integer")
except:
    print("Some error")

Refer to the exhibit. What is the output?

⚠ Common exam trap

Candidates may think that after catching an exception, the program continues to execute code that follows the try-except block, but in this question there is no such code. The trap is recognizing that the output consists solely of the print inside the except.

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 integer

The code attempts to convert the string '12.5' to an integer using int(). Since '12.5' is not a valid integer literal (it contains a decimal point), Python raises a ValueError. The exception is caught by the except clause, which prints 'Invalid integer'. After the try-except block, there is no further print statement, so the only output is 'Invalid integer'.

Answer analysis

Option-by-option breakdown

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

  • Invalid integer\nSome error

    Why it's wrong here

    Only one except block runs.

  • No output

    Why it's wrong here

    An exception is raised and caught, so a message is printed.

  • Some error

    Why it's wrong here

    The generic except is not executed because ValueError is caught first.

  • Invalid integer

    Why this is correct

    The specific ValueError handler runs.

About these practice questions

This PCEP question is part of Courseiva's 498-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.