File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""Absolute Value."""
2-
2+ from __future__ import annotations
33
44def abs_val (num : float ) -> float :
55 """
@@ -15,7 +15,7 @@ def abs_val(num: float) -> float:
1515 return - num if num < 0 else num
1616
1717
18- def abs_min (x : list [int ]) -> int :
18+ def abs_min (x : list [int | float ]) -> float :
1919 """
2020 >>> abs_min([0,5,1,11])
2121 0
@@ -35,7 +35,7 @@ def abs_min(x: list[int]) -> int:
3535 return j
3636
3737
38- def abs_max (x : list [int ]) -> int :
38+ def abs_max (x : list [int | float ]) -> float : # Changed type hint
3939 """
4040 >>> abs_max([0,5,1,11])
4141 11
@@ -50,12 +50,12 @@ def abs_max(x: list[int]) -> int:
5050 raise ValueError ("abs_max() arg is an empty sequence" )
5151 j = x [0 ]
5252 for i in x :
53- if abs (i ) > abs (j ):
53+ if abs_val (i ) > abs_val (j ):
5454 j = i
5555 return j
5656
5757
58- def abs_max_sort (x : list [int ]) -> int :
58+ def abs_max_sort (x : list [int | float ]) -> float :
5959 """
6060 >>> abs_max_sort([0,5,1,11])
6161 11
@@ -84,6 +84,10 @@ def test_abs_val():
8484 assert abs_max_sort (a ) == - 11
8585 assert abs_min (a ) == - 1
8686
87+ b = [- 3.5 , 1.2 , - 10.1 ]
88+ assert abs_max (b ) == - 10.1
89+ assert abs_min (b ) == 1.2
90+
8791
8892if __name__ == "__main__" :
8993 import doctest
You can’t perform that action at this time.
0 commit comments