absolute value def absvalnum float float return num if num 0 else num def absminx listint int if lenx 0 raise valueerrorabsmin arg is an empty sequence j x0 for i in x if absvali absvalj j i return j def absmaxx listint int if lenx 0 raise valueerrorabsmax arg is an empty sequence j x0 for i in x if absi absj j i return j def absmaxsortx listint int if lenx 0 raise valueerrorabsmaxsort arg is an empty sequence return sortedx keyabs1 def testabsval assert absval0 0 assert absval34 34 assert absval100000000000 100000000000 a 3 1 2 11 assert absmaxa 11 assert absmaxsorta 11 assert absmina 1 if name main import doctest doctest testmod testabsval printabsval34 34 find the absolute value of a number abs_val 5 1 5 1 abs_val 5 abs_val 5 true abs_val 0 0 abs_min 0 5 1 11 0 abs_min 3 10 2 2 abs_min traceback most recent call last valueerror abs_min arg is an empty sequence abs_max 0 5 1 11 11 abs_max 3 10 2 10 abs_max traceback most recent call last valueerror abs_max arg is an empty sequence abs_max_sort 0 5 1 11 11 abs_max_sort 3 10 2 10 abs_max_sort traceback most recent call last valueerror abs_max_sort arg is an empty sequence test_abs_val 34
def abs_val(num: float) -> float:
    
    return -num if num < 0 else num


def abs_min(x: list[int]) -> int:
    
    if len(x) == 0:
        raise ValueError("abs_min() arg is an empty sequence")
    j = x[0]
    for i in x:
        if abs_val(i) < abs_val(j):
            j = i
    return j


def abs_max(x: list[int]) -> int:
    
    if len(x) == 0:
        raise ValueError("abs_max() arg is an empty sequence")
    j = x[0]
    for i in x:
        if abs(i) > abs(j):
            j = i
    return j


def abs_max_sort(x: list[int]) -> int:
    
    if len(x) == 0:
        raise ValueError("abs_max_sort() arg is an empty sequence")
    return sorted(x, key=abs)[-1]


def test_abs_val():
    
    assert abs_val(0) == 0
    assert abs_val(34) == 34
    assert abs_val(-100000000000) == 100000000000

    a = [-3, -1, 2, -11]
    assert abs_max(a) == -11
    assert abs_max_sort(a) == -11
    assert abs_min(a) == -1


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    test_abs_val()
    print(abs_val(-34))