Median


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096#

Hello,
Obviously im missing something, the median returns [1] instead of 1 what makes me think im right there but i cant see it, plese help

In the mean while ill keep trying


Replace this line with your code.


#2

Looks like you might have written a return statement like this...

return [s[n]]

Please show us your code.


#3

@mtf , thanks for the reply, here is y code, also the link on the top goes to it

def median(numbers):

numbers = sorted(numbers)

if len(numbers) == 1:
    index = numbers
    return index

elif len(numbers) % 2 == 0:
    index1 = len(numbers) / 2
    index2 = index1 - 1
    index = (index2 + index1)/2.0
    return index

else:
    index = len(numbers) / 2.0
    return index

#4

This return value will be [1] since you effectively returning the list.

The remaining code is also incorrect as it focuses on the indexes, not the element values.


#5

@mtf thank you for that


#6

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