livepython.net

122. Python Program to Swap Two Numbers Using Tuple Unpacking

EasyUnpacking

Overview

The one-line swap is tuple packing and unpacking. Use it, with no temporary variable.

Problem Statement

Read two whole numbers, a and b, each on its own line. Print them, swap them with tuple unpacking, and print them again. For example, for 3 and 7:

Before: a = 3, b = 7
After: a = 7, b = 3

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

Two whole numbers, one per line. Example:

3
7

Output

The output for that example:

Before: a = 3, b = 7
After: a = 7, b = 3

The tests try 3 different inputs.

Learn this firstChapter 14 · Tuple Unpacking in Python: a, b = pair
solution.py
# write your code here

EXPECTED OUTPUT

1Before: a = 3, b = 7
2After: a = 7, b = 3

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.