-4

I am trying to make a program to calculate final grades. The user inputs x amount of assignments, and based on that I am looking to make x variables asking for the grade recieved and the weight of each assignment. For example, (user selects 20 assignments) (as input): enter assignment1 grade received, enter assignment2 grade received, ............... enter assignment20 grade received. (and the same for weights)

There needs to be a variable per assignment and I am unsure how to essentially convert an integer into a variable. (lists are not allowed). Please feel free to offer suggestions. Thanks

4

1 回答 1

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)
于 2013-09-30T01:42:06.547 回答