I found an error in the exercise, and i can"t keep going, what do i do?


#1

This is my code:

def median(LIST):
    if len(LIST) % 2 == 1:
        return LIST[(len(LIST) / 2) - 1]
    else:
        return (LIST[len(LIST)/2] + LIST[(len(LIST)/2) - 1] )/2

My code is perfectly fine, but Codecademy says: "Oops, try again. median([4, 5, 5, 4]) returned 5 instead of 4.5", which is completely wrong, because of the median of that list is in fact 5, and not 4.5. PLEASE HELP ME!!! WHAT DO I DO?? HOW DO I MOVE ON LEARNING????


#2

whoops, i wrote it wrong, I meant this (BUT EITHER WAY, CODECADEMY IS STILL WRONG, PLEASE HELP, IT WON"T LET ME MOVE ON!!!!):

def median(LIST):
    if len(LIST) % 2 == 1:
        return LIST[(len(LIST) - 1) / 2]
    else:
        return (LIST[len(LIST)/2] + LIST[(len(LIST)/2) - 1] )/2
print median([4, 5, 5, 4])

#3

Divide and integer by a float to get a float. Dividing an integer by an integer returns an integer.

This is the implict method for returning floats, and some teachers/programmers actually advise against it, in favor of explicit typing.

Naming conventions prescribe ALLCAPS to be used on global constants only, so break the practice of using that form in all other instances. Stick to lowercase. It is also recommended that we do not use reserved words or function names as variables. list() is a built-in function, so using list as a variable, while it's not hurting anything, can result in readability problems, confusion and possibly even errors.


#4

i just fixed that, but you didn't adress my issue of codecademy not understanding the median of the list [4,5,5,4]. Think to yourself, what is the median of that list? 5!!!!!! but codecademy says 4.5!!!!!! don't you see that discrepancy. Also all ur replies about list technicalities, there is in reality no significant issue with allcaps in this instance, or using the word list, im just switching it up, the point is codecademy made an error


#5

I believe it is you who are not understanding. A median is determined on a SORTED list, lowest value on the left, highest on the right.

[4,4,5,5]
(4 + 5) / 2.0 == median, 4.5

#6

OOOOOHHHHHH, why didn't you say that from the beginning, when I first asked the question? thanks, I forgot, a sorted list, oh god, wow. I am certainly increasing my capacity to make careless errors everyday. :frowning: