-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsolution.py
More file actions
34 lines (27 loc) · 916 Bytes
/
solution.py
File metadata and controls
34 lines (27 loc) · 916 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
SUBMIT = True
def simple_interest(_principal: float, _rate: float, _time: float) -> float:
# noqa: ARG001
"""Calculates simple interest using the formula: I = (P * R * T) / 100.
Example usage:
>>> simple_interest(1000, 5, 2)
100.0
>>> simple_interest(500, 3.5, 1)
17.5
"""
I=(_principal * _rate * _time) / 100
return I
def test() -> None:
"""Simple self-test for Simple Interest Calculator."""
cases = [(1000, 5, 2, 100.0), (500, 3.5, 1, 17.5)]
for p, r, t, expected in cases:
try:
res = simple_interest(float(p), float(r), float(t))
assert abs(res - expected) < 1e-9, (
f"Failed for P={p}, R={r}, T={t}: expected {expected}, got {res}"
)
except AssertionError as e:
print(f"❌ {e}")
return
print("✅ All tests passed!")
if __name__ == "__main__":
test()