PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Consider the following code: `x = 5` then `y = 2` then `result = x // y * y + x % y`. What is the value of `result`?
⚠ Common exam trap
The trap here is misapplying operator precedence, such as evaluating `*` before `//` or `%`, or misunderstanding the modulo operation.
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`
The expression combines floor division, multiplication, and modulo. Due to left-to-right evaluation of operators with equal precedence, `x // y` is computed first, then multiplied by `y`, then `x % y` is computed and added. For `x = 5` and `y = 2`, this yields `(5 // 2) * 2 + (5 % 2) = 2 * 2 + 1 = 5`. This demonstrates the relationship between floor division and modulo.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
`7`
Why it's wrong here
This would result if `x % y` were mistakenly computed as `x - (x // y)`, yielding `5 - 2 = 3`, and then added to `4` to get `7`. But `x % y` is the remainder, which is `5 % 2 = 1`. So the correct sum is `4 + 1 = 5`. The value `7` does not match the expression's evaluation.
- ✗
`6`
Why it's wrong here
This would occur if `x // y` were rounded up to `3`, giving `3 * 2 = 6`, and then `x % y` were `0`, but `5 // 2` is `2` (floor division) and `5 % 2` is `1`. So `6` is not correct. The expression evaluates to `5`.
- ✓
`5`
Why this is correct
Operator precedence: `//`, `*`, and `%` have the same precedence and are evaluated left-to-right. First `x // y` gives `2` (since `5 // 2 = 2`). Then `2 * y` gives `4`. Then `x % y` gives `1` (since `5 % 2 = 1`). Finally, `4 + 1` equals `5`. This is a standard identity: `(x // y) * y + (x % y)` reconstructs `x` for positive integers.
- ✗
`2`
Why it's wrong here
This would be the result if only `x // y` were computed, ignoring the rest. But the expression includes multiplication and modulo. The full evaluation yields `5`, not `2`. So this option ignores the `* y + x % y` part.
Go deeper
Related to this question
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 →
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.