I've read other topics as well, but I don't know how to fix this in my code.
I've tried different things to convert, but there is always the error: "TypeError: list indices must be integers, not float"
Here is my code:
def median(numbers): result =  for i in numbers: result.append(i) result = sorted(result) if len(result) % 2 == 0: print "is even." num1 = (len(result) / 2) + 1 num2 = (len(result) / 2) - 1 num = (num1 + num2) / 2 return result[num] else: print "is not even." num = len(result)/2 return result[num] print median([7, 3, 1, 4])
num1 = float((len(result) / 2) + 1) num1 = (len(result) / 2.0) + 1 num1 = (len(result) / (2.0)) + 1 num1 = (len(float(result)) / (2.0)) + 1
I don't understand it. Can you please help me and explain how I have to solve it?
I know that I have to devide float / float to get a float and not just to convert the solution to a float...