Skip to content
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

added docstring to median fn #20

Open
wants to merge 7 commits into
base: median
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ def mean(vals):
return total/length

def median(vals):
"""please implement this function"""
return 1
"""This calculates the median from a list of values"""
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."""
Expand Down
8 changes: 7 additions & 1 deletion test_stats.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nose.tools import assert_equal, assert_almost_equal, assert_true, \
assert_false, assert_raises, assert_is_instance

from stats import mean, mode, std, var#, median
from stats import mean, mode, std, var, median

def test_mean1():
obs = mean([0, 0, 0, 0])
Expand All @@ -26,6 +26,12 @@ def test_floating_mean1():
assert_equal(obs, exp)

# FIXME Put Median tests here
# I added some test that I hope work! - JYS

def test_floating_median():
obs = median([1, 2, 3])
exp = 2
assert_equal(obs, exp)

# FIXME Put Mode tests here

Expand Down