Median help 2


#1



Replace this line with your code.


def median(x):
    sorted(x)
    if len(x) % 2 != 0:
        a = x/2
        print x[a]
    elif len(x) % 2 == 0:
        a=x/2
        b = (x[a] + x[a+1])/2
        print b
    else:
        print x

Oops, try again.
median([1]) resulted in an error: unsupported operand type(s) for /: 'list' and 'int'


#2

here:

sorted(x)

you sort the list, but where do you store the sorted list?

here:

a = x/2

what is x? Its a list. list divided by 2, how does that work?


#3

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