我正在尝试制作计算最终成绩的计划。用户输入x分配数量,并根据我要求x变量询问收到的分数和每个分配的权重。 例如, (用户选择20个作业) (作为输入): 输入assignment1等级, 输入分配2等级, ............... 输入assignment20等级收到。 (和重量相同)
每个赋值需要一个变量,我不确定如何将整数转换为变量。 (不允许列表)。 请随时提供建议。感谢
答案 0 :(得分:2)
numAssigns = input("How many assignments?: ")
marks = {}
for i in range(numAssignments):
mark = input("Enter the grade obtained on assignment %s: " %i)
weight = input("Enter the weight of assignment %s: " %i)/100
if weight not in marks:
marks[weight] = {}
if mark not in marks[weight]:
marks[weight][mark] = 0
marks[weight][mark] += 1
total = 0
for weight in marks:
for mark in marks[weight]
total += mark*weight*marks[weight][mark]
print("From all your assignments, you have %s% of the total grade of the course" %total)