Do you know how to compute the median for the list the error message mentions?
If so, start comparing what your code does to that. Use prints to print out what your code does and compare. Split up long expressions if you're doing multiple things at once that you can't print. Find out exactly which operation(s) isn't doing what you think it should by printing out what you've got before and after each one (or rather, start checking somewhere in the middle of the process and then go earlier or later depending on whether it's wrong at that point)
Otherwise, figure out how to compute the median, wikipedia is a good place to start but there are probably a good couple of hundred math education sites if you google for that which also explain it