Courseiva

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

A developer wrote: x = 10; y = 5; x += y * 2. What are the values of x and y after execution?

⚠ Common exam trap

The PCEP exam often tests the misconception that `x += y * 2` means `(x + y) * 2`, leading candidates to pick 30, or that `y` is also modified, causing confusion with the assignment operator's scope.

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

✓

x=20, y=5

The expression `x += y * 2` is evaluated as `x = x + (y * 2)`. Given `x = 10` and `y = 5`, `y * 2` equals 10, then `x + 10` equals 20, so `x` becomes 20. The value of `y` remains unchanged at 5 because the assignment operator `+=` only modifies `x`.

Answer analysis

Option-by-option breakdown

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

  • ✗

    x=15, y=5

    Why it's wrong here

    Python evaluates multiplication before the augmented assignment, so y * 2 yields 10 and x becomes 20; y is untouched at 5. The option is tempting because reading left to right suggests adding y to x first, giving 15, which ignores operator precedence.

  • ✗

    x=30, y=5

    Why it's wrong here

    Multiplication binds tighter than the augmented assignment, so x += y * 2 evaluates y * 2 first, giving 10, then adds it to x for 20. Treating the expression as strictly left-to-right, (x += y) * 2, produces 30. y is never reassigned, so it stays 5.

  • ✓

    x=20, y=5

    Why this is correct

    Compound assignment evaluates the right-hand side first: y * 2 gives 10, then x += 10 adds it to the existing 10, yielding 20. Because the multiplication binds tighter than the augmented addition, y is never reassigned and retains its original value of 5, satisfying the stem's requirement.

  • ✗

    x=20, y=10

    Why it's wrong here

    The compound assignment modifies only x; y is never reassigned, so y remains 5, not 10. The value 20 is correct for x because y * 2 is evaluated before the addition, but the option also doubles y, which no operator in the statement does.

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.