-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsolution.py
More file actions
42 lines (37 loc) · 1.07 KB
/
solution.py
File metadata and controls
42 lines (37 loc) · 1.07 KB
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
36
37
38
39
40
41
42
SUBMIT = True
#ya venia con la respuesta xd
def case_inverter(s: str) -> str: # noqa: ARG001
"""
Inverts the case of each character in a string.
"""
inverted_s = ""
for char in s:
if char.islower():
inverted_s += char.upper()
elif char.isupper():
inverted_s += char.lower()
else:
inverted_s += char
return inverted_s
def test() -> None:
"""Simple self-test for Case Inverter."""
cases = [
("Hello World!", "hELLO wORLD!"),
("", ""),
("all lower", "ALL UPPER"),
("ALL UPPER", "all lower"),
("1234567890 !@#$%^&*()", "1234567890 !@#$%^&*()"),
("Python 3.12", "pYTHON 3.12"),
]
for text, expected in cases:
try:
res = case_inverter(text)
assert res == expected, (
f"Failed for text='{text}': expected {expected}, got {res}"
)
except AssertionError as e:
print(f"❌ {e}")
return
print("✅ All tests passed!")
if __name__ == "__main__":
test()