Median

Why is my code not working?

def median(inputlist):
    if len(inputlist) % 2 == 1:
        inputlist = sorted(inputlist)
        item = int(len(inputlist) / 2 - 0.5)
        answer = inputlist[item]
        return answer
    else:
        inputlist = sorted(inputlist)
        item1 = int(len(inputlist) / 2 - 1)
        item2 = int(len(inputlist) / 2)
        answer = (inputlist[item1] + inputlist[item2]) / 2
        return answer

what error do you get?

These lines have different indent levels:

        answer = (inputlist[item1] + inputlist[item2]) / 2
       return answer

why?

Oh that can be because I copy pasted it. It said that when they tried median([4,5,5,4]) it returned 4 instead of 4.5 but when I tried it out myself it returned 4.5

See? That is why its important to provide error message and thoughts (why you think this could go wrong), so we can help faster and more accurate.

as for your error, there are two major python versions (python2 and python3), and they are not backward compatible, one of the things changed is division behavior. When testing, did you take this in account?