Median: not sure why this won't work


#1

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="//codecademy-discourse.s3.amazonaws.com/original/4X/b/9/e/b9e71d961adf65a13465db865062644871995450.png" width="346" height="114">

Thanks for any help.

Dr. Cocopops


#2

Dang! Didn't load the scr shot!

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

Thanks again!
Dr. C


#3

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

Read again instructions, this is not median.


#4

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

Thanks factoradic!

Dr. C


#5

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:


#6

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

Dr. C