Skip to content

Average mean refactor #4485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Average mean refactor
Added doctests and type hints to average_mean
  • Loading branch information
haningrisha committed Jun 5, 2021
commit c036083d1eb6de64b7e9ea6b6d61de218963726c
28 changes: 13 additions & 15 deletions maths/average_mean.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
"""Find mean of a list of numbers."""


def average(nums):
"""Find mean of a list of numbers."""
return sum(nums) / len(nums)


def test_average():
def mean(nums: list) -> float:
"""
>>> test_average()
Find mean of a list of numbers.

>>> mean([3, 6, 9, 12, 15, 18, 21])
12.0
>>> mean([5, 10, 15, 20, 25, 30, 35])
20.0
>>> mean([1, 2, 3, 4, 5, 6, 7, 8])
4.5
"""
assert 12.0 == average([3, 6, 9, 12, 15, 18, 21])
assert 20 == average([5, 10, 15, 20, 25, 30, 35])
assert 4.5 == average([1, 2, 3, 4, 5, 6, 7, 8])
return sum(nums) / len(nums)


if __name__ == "__main__":
"""Call average module to find mean of a specific list of numbers."""
print(average([2, 4, 6, 8, 20, 50, 70]))
import doctest

doctest.testmod()