Median


#1


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

My code is showing syntax error. i can not find what's wrong


def median(a):
    sorted(a)
    if len(a)==1:
        median = a[0]
    elif len(a)%2==0:
        median = float(((a[len(a)/2] + a[(len(a)/2)-1])/2)
    else:
        median = int(a[len(a)/2])
    return median


#2

this line:

median = float(((a[len(a)/2] + a[(len(a)/2)-1])/2)

the number of parentheses doesn't match


#3

You call sorted(a) but then you don't store it anywhere. This means that whenever you are calling a, it is still unsorted. Try storing sorted(a) in a like this:

a = sorted(a)

#4

Thank you very much my friend :slight_smile:


#5

No problem, you're welcome.


#6