Skip to content

Commit ae613de

Browse files
refactor(maths): clean up abs.py code style and remove print statement
- Standardized absolute value calls in abs_min to use built-in abs() - Removed redundant print call from main block for cleaner test execution - Improved doctest formatting and type annotations
1 parent 0a72d14 commit ae613de

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

‎maths/abs.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def abs_val(num: float) -> float:
1717

1818
def abs_min(x: list[int]) -> int:
1919
"""
20-
>>> abs_min([0,5,1,11])
20+
>>> abs_min([0, 5, 1, 11])
2121
0
22-
>>> abs_min([3,-10,-2])
22+
>>> abs_min([3, -10, -2])
2323
-2
2424
>>> abs_min([])
2525
Traceback (most recent call last):
@@ -30,16 +30,16 @@ def abs_min(x: list[int]) -> int:
3030
raise ValueError("abs_min() arg is an empty sequence")
3131
j = x[0]
3232
for i in x:
33-
if abs_val(i) < abs_val(j):
33+
if abs(i) < abs(j):
3434
j = i
3535
return j
3636

3737

3838
def abs_max(x: list[int]) -> int:
3939
"""
40-
>>> abs_max([0,5,1,11])
40+
>>> abs_max([0, 5, 1, 11])
4141
11
42-
>>> abs_max([3,-10,-2])
42+
>>> abs_max([3, -10, -2])
4343
-10
4444
>>> abs_max([])
4545
Traceback (most recent call last):
@@ -57,9 +57,9 @@ def abs_max(x: list[int]) -> int:
5757

5858
def abs_max_sort(x: list[int]) -> int:
5959
"""
60-
>>> abs_max_sort([0,5,1,11])
60+
>>> abs_max_sort([0, 5, 1, 11])
6161
11
62-
>>> abs_max_sort([3,-10,-2])
62+
>>> abs_max_sort([3, -10, -2])
6363
-10
6464
>>> abs_max_sort([])
6565
Traceback (most recent call last):
@@ -89,6 +89,3 @@ def test_abs_val() -> None:
8989
import doctest
9090

9191
doctest.testmod()
92-
93-
test_abs_val()
94-
print(abs_val(-34)) # --> 34

0 commit comments

Comments
 (0)