PCEP Computer Programming and Python Fundamentals Practice Question
A junior developer writes a Python script to calculate the average of three numbers: avg = a + b + c / 3. What is the problem with this code?
⚠ Common exam trap
The PCEP exam often tests the misconception that Python evaluates expressions strictly left-to-right, leading candidates to think `a + b + c / 3` works correctly, when in fact operator precedence overrides left-to-right evaluation.
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
✓
Missing parentheses cause incorrect order of operations
Python follows the standard mathematical order of operations (PEMDAS/BODMAS), where division has higher precedence than addition. The expression `a + b + c / 3` is evaluated as `a + b + (c / 3)`, which calculates the average incorrectly. To compute the correct average, parentheses must be used: `(a + b + c) / 3`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Division by a variable is not allowed
Why it's wrong here
Division by a variable is perfectly valid.
- ✓
Missing parentheses cause incorrect order of operations
Why this is correct
Division has higher precedence than addition, so parentheses are needed to group the sum.
- ✗
Python cannot divide integers
Why it's wrong here
Python can divide integers; the result is a float.
- ✗
Variable names are too short
Why it's wrong here
Short variable names are syntactically valid.
Go deeper
Related to this question
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 →
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.