From 384b50eb157337a66e16f258babee60a080fcdcc Mon Sep 17 00:00:00 2001 From: Pamela Oliver Date: Thu, 4 Jun 2015 15:29:11 -0500 Subject: [PATCH 1/3] I added a median function from beta --- stats.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stats.py b/stats.py index e1dd7c3..e7bc14d 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() + 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.""" From 366696f80f4972e9c87ed2bba5b297a420249eee Mon Sep 17 00:00:00 2001 From: CHRISTINA EWIG Date: Thu, 4 Jun 2015 15:55:27 -0500 Subject: [PATCH 2/3] I added something to test_stats.py --- test_stats.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 From d19fe531a373274a86297ee2c752d3b8fa74c12c Mon Sep 17 00:00:00 2001 From: Tenayuca Date: Thu, 4 Jun 2015 16:03:45 -0500 Subject: [PATCH 3/3] Update stats.py --- stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stats.py b/stats.py index e7bc14d..1c6ffa1 100644 --- a/stats.py +++ b/stats.py @@ -13,7 +13,7 @@ def mean(vals): def median(vals): """please implement this function""" vals.sort() - z = len(vals) + list= z = len(vals) index = z / 2 if z % 2 == 0: return mean([vals[index], vals[index - 1]])