n = float(input("请输入科目数量:"))
numbers = []
credits = []
weights = []
fcredits=[]
numbers = input('请输入一组成绩(以空格隔开,按回车结束):').split(' ')
credits = input('请输入分数对应科目的学分(以空格隔开,按回车结束):').split(' ')
i = int(0)
c = float(0)
b = float(0)
a = int(0)
while a<n: #使分数变为浮点数
numbers[a] = float(numbers[a])
a = a+1
for credit in credits:
credit = float(credit) #使学分变为浮点数
fcredits.append(credit) #存储浮点类型的学分
c = c+credit #求总学分
for credit in credits:
credit = float(credit) / c #求每一科权重
weights.append(credit) #储存每一科权重
while i<n:
b=b+numbers[i]*weights[i] #依据权重和每一科分数,求总分
i=i+1
break
print(fcredits)
print(numbers)
print(weights)
print(b)
print(a)
这段代码的第28行,如果把break去掉,就会提示第26行的列表超出范围。为什么会这样呢?当i=n的时候while循环不是停止了吗?