Median


#1



Median

The error says Ops, tente outra vez. median([1]) returned [1] instead of 1

How do I get the parenthesis out so I am able to return 1 instead of [1]?

Here is my code
 

def median(x):
    a = sorted(x)
    middle = a[len(a) / 2]
    firstmiddle = a[len(a) / 2]
    secondmiddle = a[len(a) / 2  - 1]
    if len(a) % 2 == 0 and len(a) != 1:
        evendataset = (firstmiddle + secondmiddle) / 2
        return evendataset
    elif len(a) == 1:
        return a
    else:
        return middle


#2

here is the link to the excersise

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


#3

@thebeaver,
You will have to change your

    elif len(a) == 1:
        return a

into

    elif len(a) == 1:
        return a[0]

#4

oh is it because if i just return a it will return the whole list, and not just the single number in the list?


#5

Yes, "return a" will return the whole list