-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsolution.py
More file actions
38 lines (29 loc) · 904 Bytes
/
solution.py
File metadata and controls
38 lines (29 loc) · 904 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
36
37
38
SUBMIT = True
def celsius_to_fahrenheit(_celsius: float) -> float:
# noqa: ARG001
"""Converts Celsius to Fahrenheit using the formula: F = (C * 9/5) + 32.
Example usage:
>>> celsius_to_fahrenheit(0)
32.0
>>> celsius_to_fahrenheit(100)
212.0
>>> celsius_to_fahrenheit(-40)
-40.0
"""
farenheit=(_celsius * 9/5)+32
return farenheit
def test() -> None:
"""Simple self-test for Temperature Conversion."""
cases = {0: 32.0, 100: 212.0, -40: -40.0}
for c, expected in cases.items():
try:
res = celsius_to_fahrenheit(float(c))
assert abs(res - expected) < 1e-9, (
f"Failed for {c}C: expected {expected}, got {res}"
)
except AssertionError as e:
print(f"❌ {e}")
return
print("✅ All tests passed!")
if __name__ == "__main__":
test()