Courseiva
Computer Programming and Python FundamentalseasyMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

Exhibit

NameError: name 'x' is not defined

Refer to the exhibit. What is the most likely cause of this error?

⚠ Common exam trap

The PCEP exam often tests the distinction between a variable being undefined versus being of a certain type, tricking candidates into thinking the error is about type mismatch when it is actually about the variable not existing yet.

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

Variable x is used before assignment

The error message indicates that variable 'x' is being referenced before it has been assigned a value. In Python, using a variable that has not been defined yet raises a NameError. Option B correctly identifies this as the cause.

Answer analysis

Option-by-option breakdown

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

  • Variable x is a string

    Why it's wrong here

    A string variable would not cause a NameError.

  • Variable x is used before assignment

    Why this is correct

    This is the typical cause of a NameError in Python.

  • Variable x is an integer

    Why it's wrong here

    An integer variable would not cause a NameError.

  • Variable x is misspelled

    Why it's wrong here

    Misspelling would likely cause a similar error, but the most direct cause is that x was never assigned.

About these practice questions

Courseiva writes every PCEP question from scratch — 498 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.