Answer:
Here is the Python program:
test_grades = [101, 83, 107, 90] # list of test grades
sum_extra = 0 # stores total sum of extra credit
for i in test_grades: #loop to check extra credit in test grades
if i > 100: # if grade is greater than 100
i = i - 100 # 100 is subtracted from grade
else: # otherwise
i = 0
sum_extra = sum_extra + i #adds i to to sum_extra
print('Sum extra is:', sum_extra) # prints the value of sum_extra
Step-by-step explanation:
This program assigns sum_extra with total extra credit received in list test_grades. Lets see how this program works step wise.
We have a list with the following elements 101, 83, 107 and 90
sum_extra is initialized to 0
For loop has variable i that works like an index and moves through the list of test_grades
First i is positioned at 101. If condition in the loop checks if the element at i-th position is greater than 100. It is true because 101 > 100. So 100 is subtracted from 101 and i becomes 1. So this statement is executed next sum_extra = sum_extra + i
= 0 + 1
So the value of sum_extra = 1
Next i is positioned at 83. If condition in the loop checks if the element at i-th position is greater than 100. It is false to i become 0.So this statement is executed next sum_extra = sum_extra + i
= 1 + 0
So the value of sum_extra = 1
Next i is positioned at 107. If condition in the loop checks if the element at i-th position is greater than 100. It is true because 107 > 100. So 100 is subtracted from 107 and it becomes 7. So this statement is executed next sum_extra = sum_extra + i
= 1 + 7
So the value of sum_extra = 8
Next i is positioned at 90. If condition in the loop checks if the element at i-th position is greater than 100. It is false to i become 0.So this statement is executed next sum_extra = sum_extra + i
= 8 + 0
So the value of sum_extra = 8
So the output of the above program is 8.
Output:
Sum extra is: 8