I am writing a basic program in Python that prompts the user to enter 5 test scores. The program will then convert each test score to a grade point (i.e. 4.0, 3.0, 2.0...), and then afterwards take the average of these numbers.
I've assigned each test score their own variable, and I'm feeding them into a for loop as follows:
for num in [score1, score2, score3, score4, score5]:
if num >= 90
print('Your test score is a 4.0')
elif num < 90 and >= 80
.
.
# and so on for each grade point.
Now, this does fine for displaying what each test score is equivalent to grade point wise. However, later in the function I need to calculate the average of each of these grade point values. So, I'd actually like to assign a grade point value to the specific variable passed through the for loop at that time. So, when score1 is passed through the for loop, and the appropriate grade point is determined, how can I actually assign that grade point to score1, and then later for score2 and so on as they are passed through the loop?
I hope that makes the question clear. It would seem silly that Python would not have this kind of capability, because if not you wouldn't be able to redefine any variable passed through a for loop if it is part of a list that is being passed through.
Not only are variables "in" the list (the list actually only stores values) updated, but the list isn't updated at all by this process. See Why doesn't assigning to the loop variable modify the original list? How can I assign back to the list in a loop? for that version of the question.