Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A junior developer writes the following code to swap two variables: a = 5; b = 10; a = b; b = a. When they print a and b, what is the output?

⚠ Common exam trap

The PCEP exam often tests the misconception that `b = a` after `a = b` somehow retrieves the original value of `a`, when in fact the original value is already overwritten.

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

✓

10 10

After `a = b`, both variables hold the value 10. Then `b = a` assigns the current value of `a` (which is now 10) to `b`, so both remain 10. The original value of `a` (5) is lost because it was overwritten before being saved.

Answer analysis

Option-by-option breakdown

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

  • ✓

    10 10

    Why this is correct

    The first assignment a = b overwrites a with 10, destroying the original 5. The second assignment b = a then copies 10 back into b, so both variables hold 10; no temporary variable preserved the original value.

  • ✗

    5 5

    Why it's wrong here

    After a = b, a holds 10, so b = a leaves b at 10; the output is 10 10, not 5 5. The 5 5 result is tempting because it looks like a partial swap, but no assignment in this sequence can restore the original value 5 to either variable.

  • ✗

    5 10

    Why it's wrong here

    After a = b, both variables hold 10, so b = a assigns 10 again; printing yields 10 10, not 5 10. The 5 10 output is tempting because it matches the pre-swap state, which would only appear if the assignments were never executed.

  • ✗

    10 5

    Why it's wrong here

    The second assignment b = a reads the already-overwritten a, which holds 10, so b becomes 10 and both print 10 10. This option is tempting because 10 5 is the genuine swapped result, achievable only with a temporary variable or tuple assignment such as a, b = b, a.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.