GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python/maths/average_absolute_deviation.py at master · pythogasm/Python Expand file tree/ Copy pathaverage_absolute_deviation.pyMore file actions 29 lines (24 loc) · 859 Bytes / Copy pathaverage_absolute_deviation.pyFile metadata and controls29 lines (24 loc) · 859 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 def average_absolute_deviation(nums: list[int]) -> float: """ 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 """ if not nums: # Makes sure that the list is not empty raise ValueError("List is empty") average = sum(nums) / len(nums) # Calculate the average return sum(abs(x - average) for x in nums) / len(nums) if __name__ == "__main__": import doctest doctest.testmod() |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |