15/15 Median: why isn'y my code working


My Code isnt working

def median(lst):
median = 0
while lst:
if len(lst) % 2 == 0:
upper = lst[len(lst) / 2 - 1]
lower = lst[len(lst) / 2]
median = (upper + lower) / 2.0
median += lst[len(lst) / 2]
return median

This is my code. it seems right but it just doesn't seem to get the right answers

Replace this line with your code.


This is not doing what you might expect.

lst.sort()             # in place sort, no copy made

lists = sorted(lst)    # copy made and sorted, original unchanged.

Please help us understand what this loop is doing?

Please explain why we would need to run an accumulator?


wow thanks man it worked


idk all that stuff is useless when i look back on it u could easily take out the accumulator and the loop because they do nothing i rushed this a bit


What's the hurry? I thought this is supposed to be a practice session?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.