-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsolution.py
More file actions
35 lines (27 loc) · 802 Bytes
/
solution.py
File metadata and controls
35 lines (27 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from typing import Any
SUBMIT = True
def variable_swap(a: Any, b: Any) -> tuple[Any, Any]:
"""Swaps the values of a and b.
Example usage:
>>> variable_swap(5, 10)
(10, 5)
>>> variable_swap("hello", "world")
('world', 'hello')
"""
a,b=b,a
return a, b
def test() -> None:
"""Simple self-test for Variable Swap."""
cases = [(5, 10, (10, 5)), ("apple", "banana", ("banana", "apple"))]
for a, b, expected in cases:
try:
res = variable_swap(a, b)
assert res == expected, (
f"Failed for a={a}, b={b}: expected {expected}, got {res}"
)
except AssertionError as e:
print(f"❌ {e}")
return
print("✅ All tests passed!")
if __name__ == "__main__":
test()