Skip to content
Snippets Groups Projects
Commit 70d8dc82 authored by Studer Gabriel's avatar Studer Gabriel
Browse files

enforce integer division

in Python 2: 1/2=0 in Python 3: 1/2 = 0.5
parent 2aff0066
No related branches found
No related tags found
No related merge requests found
......@@ -15,10 +15,11 @@ def Median(xs):
if len(xs)==0:
raise RuntimeError("Can't calculate median of empty sequence")
sorted_xs=sorted(xs)
central_idx = int((len(xs)-1)/2)
if (len(xs) % 2)==0:
return (sorted_xs[(len(xs)-1)/2]+sorted_xs[(len(xs)-1)/2+1])/2.0
return (sorted_xs[central_idx]+sorted_xs[central_idx+1])/2.0
else:
return sorted_xs[(len(xs)-1)/2]
return sorted_xs[central_idx]
def StdDev(xs):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment