Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

A developer writes: a = 3; b = 4; c = a + b / 2. What is the value of c?

⚠ Common exam trap

Python Institute often tests the combination of operator precedence and the fact that `/` always returns a float in Python 3, trapping candidates who expect integer division or who incorrectly group the expression as `(a + b) / 2`.

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

✓

5.0

In Python, the division operator `/` always returns a float, and operator precedence dictates that division is performed before addition. Thus, `b / 2` evaluates to `4 / 2 = 2.0`, then `a + 2.0` yields `3 + 2.0 = 5.0`. Option D is correct because the result is a float value of 5.0.

Answer analysis

Option-by-option breakdown

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

  • ✗

    3

    Why it's wrong here

    Division binds tighter than addition, so b / 2 evaluates to 2.0 and 3 + 2.0 gives 5.0, not 3. It tempts if you misread the expression as (a + b) / 2, which would be 3.5, or assume integer truncation discards the fractional part.

  • ✗

    3.5

    Why it's wrong here

    The result is 5.0, not 3.5: b / 2 is 2.0, and 3 + 2.0 yields 5.0. It tempts because 3.5 is exactly what (a + b) / 2 produces, so grouping the addition first — the natural reading of a written fraction — gives this value.

  • ✗

    5

    Why it's wrong here

    The value is 5.0, a float, not the integer 5, because true division always returns a float in Python 3. It tempts since 5 is the correct numeric magnitude, and integer division or floor rounding would indeed produce a whole number here.

  • ✓

    5.0

    Why this is correct

    Division precedes addition, so b / 2 evaluates first as 4 / 2, yielding the float 2.0. Adding a (3) gives 5.0, and because true division always returns a float, the result is 5.0 rather than integer 5.

About these practice questions

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