0

I have a dictionary of names of students and their grades. I need to calculate the percentage of these grades and it's weight ( (grade/point)*100 ) and then update their values with the new grades.

I have the following code but the problem is that when I print the dictionary it gives me the old numbers. How can I change the values of the dictionary into the ones after I made the calculations?

maxx = 50
perecent = 100

grades = {'a':36, 'b':25, 'c':43}

for u in grades.values():
    w = ((u/maxx)*(perecent))
    print(w)

print(grades)

The output of this is:

72
86
50
{'a': 36, 'c': 43, 'b': 25}

while I need:

72
86
50
{'a': 72, 'c': 86, 'b': 50}

1 Answer 1

1
for (key, u) in grades.items():
  w = ((u/maxx)*(perecent))
  print(w)
  grades[key] = w
print(grades)

Using key to look up a dictionary entry should effect a change in the value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.