✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
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
Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!