Skip to content

Commit e88e1fd

Browse files
authored
Merge pull request #21 from UBC-MDS/mean-function
Mean function
2 parents c7d5ab7 + 47eadc5 commit e88e1fd

File tree

4 files changed

+105
-41
lines changed

4 files changed

+105
-41
lines changed

src/dumbpy/arithmetic_mean.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
A module that calculates the arithmetic mean of a list of numbers
3+
4+
"""
5+
6+
from support_functions import *
7+
8+
def arithmetic_mean(values: list[float | int]):
9+
"""
10+
Calculate the arithmetich mean of the inputted list and return the result.
11+
12+
Parameters
13+
----------
14+
values : list[float | int]
15+
A list of numbers.
16+
17+
Returns
18+
-------
19+
float
20+
The arithmetic mean of the list of numbers.
21+
22+
Examples
23+
--------
24+
>>> arithmetic_mean([1, 2, 3, 4])
25+
2.5
26+
"""
27+
pass

src/dumbpy/example.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/dumbpy/std_deviation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
44
"""
55

6-
def std_deviation(input):
6+
from support_functions import *
7+
8+
def std_deviation(values: list[float | int]):
79
"""
810
Calculate the standard deviation of the inputted list and return the result.
911
1012
Parameters
1113
----------
12-
input : list
14+
values : list[float | int]
1315
A list of numbers.
1416
1517
Returns
@@ -21,8 +23,6 @@ def std_deviation(input):
2123
--------
2224
>>> std_deviation([1, 1, 1, 1])
2325
0
24-
>>> add_numbers([1, 0, 1, 0])
25-
0.5
26-
2726
"""
27+
pass
2828

src/dumbpy/support_functions.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
A module of support functions for the dumbpy main functionality
3+
4+
"""
5+
6+
from typing import Any
7+
8+
def validate_types(values: Any):
9+
"""
10+
Validate that the input is an iterable of numeric values.
11+
12+
This function checks whether the provided input is an iterable
13+
containing only numeric types (integers or floats). If the input
14+
is not iterable or contains non-numeric values, a TypeError is raised.
15+
16+
Parameters
17+
----------
18+
values : Any
19+
Any input provided by the user.
20+
21+
Raises
22+
------
23+
TypeError
24+
If `values` is not iterable or if any element in `values`
25+
is not a numeric type.
26+
27+
Examples
28+
--------
29+
>>> validate_types([1, 2, 3.5])
30+
>>> validate_types((1, 2, 3))
31+
>>> validate_types([1, "a", 3])
32+
Traceback (most recent call last):
33+
...
34+
TypeError: All elements must be numeric.
35+
"""
36+
pass
37+
38+
def flatten_list(values: list):
39+
"""
40+
Flatten a nested list into a single, one-dimensional list.
41+
42+
This function takes a list that may contain nested lists and
43+
returns a new list with all elements flattened into a single
44+
level, preserving their original order.
45+
46+
Parameters
47+
----------
48+
values : list
49+
A list that may contain nested lists of arbitrary depth.
50+
51+
Returns
52+
-------
53+
list
54+
A flattened list containing all elements from `values`.
55+
56+
Raises
57+
------
58+
TypeError
59+
If `values` is not a list.
60+
61+
Examples
62+
--------
63+
>>> flatten_list([1, 2, [3, 4]])
64+
[1, 2, 3, 4]
65+
66+
>>> flatten_list([[1, 2], [3, [4, 5]]])
67+
[1, 2, 3, 4, 5]
68+
69+
>>> flatten_list([])
70+
[]
71+
"""
72+
pass
73+

0 commit comments

Comments
 (0)