PCEP Computer Programming and Python Fundamentals Practice Question
Exhibit
Refer to the exhibit.
Traceback (most recent call last):
File "script.py", line 3, in <module>
print(result)
NameError: name 'result' is not definedA developer runs the code from the exhibit and gets the error shown. Which of the following is the most likely cause?
⚠ Common exam trap
The PCEP exam often tests the distinction between a variable that exists but has the wrong type (TypeError) and a variable that has never been assigned (NameError), leading candidates to incorrectly focus on type mismatches instead of the missing assignment.
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
✓
The variable 'result' was never assigned a value.
The error message indicates that the variable 'result' is referenced before it has been assigned any value. In Python, using a variable that has never been assigned raises a NameError. The code attempts to print 'result', but no assignment to 'result' exists in the provided code, so Python cannot resolve the name.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
There is a typo in the variable name.
Why it's wrong here
Plausible but less specific.
- ✓
The variable 'result' was never assigned a value.
Why this is correct
NameError occurs when variable is not defined.
- ✗
The print function requires an import.
Why it's wrong here
print is built-in.
- ✗
The variable 'result' is a string, not an integer.
Why it's wrong here
Type mismatch doesn't cause NameError.
Visual reference
Go deeper
Related to this question
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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Refer to the exhibit. What is the most likely cause of this error?
easy- A.Variable x is a string
- ✓ B.Variable x is used before assignment
- C.Variable x is an integer
- D.Variable x is misspelled
Why B: 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.
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.