✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Task 2: Swapping Two Variables (Multiple Methods)
Objective: Practice variable swapping using different techniques.
Instructions:
Write a Python function swap_with_temp(a, b) that:
Swaps two variables using a temporary variable.
Write another function swap_without_temp(a, b) that:
Swaps two variables using arithmetic operations (addition and subtraction).
(Optional Advanced) Try swapping using a Python tuple assignment in a single line.
Example Input:
a = 100, b = 200
Expected Output for all methods:
a = 200, b = 100
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!