Median: not sure why this won't work


Without realising it I had accidentally defined it twice and was getting the "median[1] returned [1] instead of 1." error, but now that I removed the second definition I get "Oops, try again. median([1]) returned 0.5 instead of 1"

Maybe I've been staring at it too long but I don't see the error!

<img src="//" width="346" height="114">

Thanks for any help.

Dr. Cocopops


Dang! Didn't load the scr shot!

def median(lst):
....lst = float(len(sorted(lst)))/2
....return lst

Thanks again!
Dr. C


Your function returns length of the list divided by two :slight_smile:

Read again instructions, this is not median.


Darn, I thought I had managed an answer despite my meager math skills!

Thanks factoradic!

Dr. C


You are pretty close to the right answer. Just add if ... else, index operator and done :slight_smile:

In case of further problems, just let us know and we will help :slight_smile:


Thanks. I quite liked the way the code looked. I kinda wanted to keep it! (If it works that is.)

Dr. C