diff --git a/stats.py b/stats.py index e1dd7c3..1c6ffa1 100644 --- a/stats.py +++ b/stats.py @@ -12,7 +12,13 @@ def mean(vals): def median(vals): """please implement this function""" - return 1 + vals.sort() + list= z = len(vals) + index = z / 2 + if z % 2 == 0: + return mean([vals[index], vals[index - 1]]) + else: + return vals[index] def mode(vals): """Computes the mode from a list of values.""" diff --git a/test_stats.py b/test_stats.py index 5d43eeb..d2802bf 100644 --- a/test_stats.py +++ b/test_stats.py @@ -3,6 +3,17 @@ from stats import mean, mode, std, var#, median + +def test_median(vals): + "my test" + vals.sort() + z = len(vals) + index = z / 2 + if z % 2 == 0: + return mean([vals[index], vals[index - 1]]) + else: + return vals[index] + def test_mean1(): obs = mean([0, 0, 0, 0]) exp = 0