My code is correct but just can’t pass. Practice Makes Perfect.median


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5


When I clicked the “Save & Submit code” bottom, it popped out a window which said

“Something went wrong : (
Click Close to try again or refresh the page.”

Console outputted

"Traceback (most recent call last):
File “python/cli_runner.py”, line 152, in < module >”


I try my code in own computer, it was correct. Input all the examples the task used, and it all returned correct answers. It made me wonder was my code wrong or there was something wrong with the CodeCademy.


def median(x):
    x = sorted(x)
    middle = (len(x) + 1) / 2 - 1
    middle2 = len(x) / 2
    return (x[middle] + x[middle2]) / 2.0


#2

the parentheses you use in this line:

    middle = (len(x) + 1) / 2 - 1

the outer parentheses are not normal parentheses, see the difference between and )? Please use the normal parentheses


#3

Thx. I must be more careful afterwards.:grinning:


#4