我有一个错误的问题:
TypeError: list indices must be integers or slices, not float
在下面我的代码的这一行:
a1[j+1] = key
下面是我的代码:
a1 = [4.3, 5.2, 5.0, 1.5, 3.8, 4.1, 5.5, 1.9]
sum = 0
count = len(a1)
for i in a1:
sum = sum + float(i)
key = a1[index]
j = i-1
while j >= 0 and key < j :
a1[j + 1] = a1[j]
j -= 1
a1[j+1] = key
mean = sum/count
print("Answer for y = 1.5")
print("Average: {0}".format(mean))
我想要一个插入排序来对数组 a1 进行排序