Respuesta :
Answer:
Complete python code with explanation and output results is given below.
Explanation:
We have a list of grades test_grades and some of those grades have received extra credit and therefore, their grade is greater than 100.
Now we have to sum all these extra credit from each grade that is greater than 100
Please note that I have created another test_grades2 list to verify and be sure whether program is showing correct results or not.
Python Code:
# lists of grades
test_grades = [101, 83, 107, 90]
test_grades2 = [105, 108, 103, 90, 104, 78]
# to do the sum we have used the sum() function and a for loop runs through entire list to check the condition grade>100 if condition is true then minus 100 from it and keep adding it in the sum_extra.
sum_extra = sum([grade - 100 for grade in test_grades if grade > 100])
sum_extra2 = sum([grade2 - 100 for grade2 in test_grades2 if grade2 > 100])
# then finally print the sum_extra
print('Sum extra: '+str(sum_extra)+' for test_grades')
print('Sum extra: '+str(sum_extra2)+' for test_grades2')
Output:
Sum extra: 8 for test_grades
Sum extra: 20 for test_grades2
The results are correct and the program is working correctly as it was required.
Note: feel free to ask in the comment if you don't understand anything
![Ver imagen nafeesahmed](https://us-static.z-dn.net/files/d6c/e1c6b3857a2d2c276b679181eda7f74b.png)
Answer:
user_input = input()
test_grades = list(map(int, user_input.split())) # test_grades is an integer list of test scores
sum_extra = -999 # Initialize 0 before your loop
sum_extra = sum(grade - 100 for grade in test_grades if grade > 100)
print('Sum extra:', sum_extra)
Explanation:
Hopefully that helps! I struggled with the "in" and "if" and it took a while to realize I could put them in one line.