PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A programmer writes the following code to calculate the average of two numbers:
a = 5 b = 2 avg = a / b
print(avg)
What is the output?
⚠ Common exam trap
The trap here is assuming that division of two integers yields an integer, as in some other programming languages, but Python's / operator always returns a float.
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
✓
2.5
In Python 3, the / operator performs true division and always returns a float. With a = 5 and b = 2, a / b evaluates to 2.5. The other options reflect common mistakes: confusing / with //, truncating the result, or assuming an error where none exists. The correct output is 2.5.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Error: division by zero
Why it's wrong here
The divisor b is 2, not zero, so no division by zero error occurs. A ZeroDivisionError would only happen if b were 0. Since b is 2, the division proceeds normally and returns 2.5. This option misidentifies the value of b, leading to an incorrect error prediction.
- ✗
2
Why it's wrong here
The // operator performs floor division, which would yield 2, but the code uses /, not //. The / operator returns a float, so the result is 2.5. This option incorrectly assumes integer division or truncation. In Python 3, / always produces a float, even if the division is exact.
- ✗
2.0
Why it's wrong here
While 2.0 is a float, it is not the exact result of 5 / 2. The true division of 5 by 2 yields 2.5, not 2.0. This option might arise from confusing true division with floor division followed by a float conversion, but the / operator does not truncate. Thus, 2.0 is incorrect.
- ✓
2.5
Why this is correct
The division operator / in Python performs true division, returning a float result even when both operands are integers. Here, 5 / 2 equals 2.5. Therefore, the print statement outputs 2.5. This is the correct behavior for the / operator, which always returns a floating-point number.
Go deeper
Related to this question
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 →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.