Courseiva

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

    Python divides by variables freely; the divisor here is the literal 3, not a variable. Variable divisors are valid in any expression, and would be relevant only if the language restricted runtime division, which Python does not.

  • ✓

    Missing parentheses cause incorrect order of operations

    Why this is correct

    Division binds tighter than addition, so a + b + c / 3 computes a + b + (c/3), not (a+b+c)/3. Wrapping the sum in parentheses restores the intended grouping, satisfying the stem's requirement for a correct average calculation across all three numbers.

  • ✗

    Python cannot divide integers

    Why it's wrong here

    Python's / operator returns a float for integer operands, so integer division is permitted. True integer truncation occurs with //, and would be the issue only if the script required floor division semantics rather than a correct average.

  • ✗

    Variable names are too short

    Why it's wrong here

    Name length has no bearing on evaluation; Python binds any valid identifier. Short names are merely a readability concern, and would be the answer only if the question asked about style or maintainability rather than operator precedence.

About these practice questions

One of 482 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.