n = int(input("请输入科目数量:"))
numbers = []
credits = []
weight = []
numbers = input('请输入一组成绩(以空格隔开,按回车结束):').split(' ')
credits = input('请输入分数对应科目的学分(以空格隔开,按回车结束):').split(' ')
c = 0
float(c)
for credit in credits:
credit = float(credit)
c = c+credit
break
i = int(0)
while i<n:
numbers[i]=credits[i]/c
break
b=0
for a in range(n):
b=b+float(numbers[a])
print(b)
这是一个求加权平均分的程序。
错误提示:
Traceback (most recent call last):
File "F:\pythonProject\main.py", line 18, in <module>
numbers[i]=credits[i]/c
TypeError: unsupported operand type(s) for /: 'str' and 'float'