05.02 · Swap values and compare sets / Practice · 11 min
Complete the three original swaps
Each pair must retain both original values, just under the opposite names.
Activity 2 of 6 in Swap values and compare sets
Python 3: Lists / 05.02
Practice value swapping
Not started
Exchange the source numeric and name values while keeping each technique visible.
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Your task: three methods
Keep x=100 and y=200; exchange them using a temporary variable. Print x, then y.
Keep m=8 and n=12; use the source’s addition/subtraction sequence to swap their values. Print m, then n.
Keep first_name="John" and last_name="Doe"; exchange them using paired assignment. Print first_name, then last_name. Expect six lines: 200, 100, 12, 8, Doe, John.
Trace the intermediate values
The checks inspect final named values and output, not which swapping technique produced them. Review the requested method in each section. After passing, try equal values and a negative numeric value. Restore the original inputs for the checks.
Build it one step at a time
Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)4 steps · Saved work · Instant feedback
YOUR TURN
Swap three pairs without losing values
Use a temporary name for x/y, arithmetic for m/n and paired assignment for first_name/last_name. Print each pair after its swap in the requested order.
200 100 12 8 Doe John
Keep the starting inputs. Print these lines in this order, without extra output.
- Store the requested x
- Store the requested y
- Store the requested m
- Store the requested n
- Store the requested first name
- Store the requested last name
- Output 1 matches the requested result
- Output 2 matches the requested result
- Output 3 matches the requested result
- Output 4 matches the requested result
- Output 5 matches the requested result
- Output 6 matches the requested result
Edit Python, then run it. Check challenge checks your output and the listed Python requirements. Your code saves on this browser after a short pause. Sign in and choose Save account draft to keep it across devices. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Need a nudge?
Preserve the original before replacing it
Save the original x in temporary, then assign y to x and temporary to y.
The right side is evaluated first
first_name, last_name = last_name, first_name uses both original values before assigning the two targets.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
Each result retains both original values under the opposite names. The temporary, arithmetic and paired-assignment versions express the exchange differently.
Walk through the fix.
Choose Next to inspect one change at a time. Highlighted lines show what to notice. Your editor stays unchanged unless you choose to load a step.
Step 1 of 2
Read the starting values
Identify the original values and what must remain unchanged.
x = 100Expected output for this step
(No output)
Follow the change and compare results
Each result retains both original values under the opposite names. The temporary, arithmetic and paired-assignment versions express the exchange differently.
x = 100
y = 200
temporary = x
x = y
y = temporary
print(x)
print(y)
m = 8
n = 12
m = m + n
n = m - n
m = m - n
print(m)
print(n)
first_name = "John"
last_name = "Doe"
first_name, last_name = last_name, first_name
print(first_name)
print(last_name)Expected output for this step
200 100 12 8 Doe John
See the complete solution
x = 100
y = 200
temporary = x
x = y
y = temporary
print(x)
print(y)
m = 8
n = 12
m = m + n
n = m - n
m = m - n
print(m)
print(n)
first_name = "John"
last_name = "Doe"
first_name, last_name = last_name, first_name
print(first_name)
print(last_name)Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in