return the average absolute deviation of a list of numbers wiki https en wikipedia orgwikiaverageabsolutedeviation averageabsolutedeviation0 0 0 averageabsolutedeviation4 1 3 2 1 0 averageabsolutedeviation2 70 6 50 20 8 4 0 20 0 averageabsolutedeviation20 0 30 15 16 25 averageabsolutedeviation traceback most recent call last valueerror list is empty return the average absolute deviation of a list of numbers wiki https en wikipedia org wiki average_absolute_deviation average_absolute_deviation 0 0 0 average_absolute_deviation 4 1 3 2 1 0 average_absolute_deviation 2 70 6 50 20 8 4 0 20 0 average_absolute_deviation 20 0 30 15 16 25 average_absolute_deviation traceback most recent call last valueerror list is empty makes sure that the list is not empty calculate the average
def average_absolute_deviation(nums: list[int]) -> float:
    
    if not nums:  
        raise ValueError("List is empty")

    average = sum(nums) / len(nums)  
    return sum(abs(x - average) for x in nums) / len(nums)


if __name__ == "__main__":
    import doctest

    doctest.testmod()