# Assign sum_extra with the total extra credit received given list test_grades. Full credit is 100, so anything over 100 is extra credit. For the given program, sum_extra is 8 because 1 + 0 + 7 + 0 is 8. Sample output for the given program:

test_grades = [101, 83, 107, 90]
sum_extra = -999 # Initialize 0 before your loop
sum_extra = 0
for grade in test_grades:
if grade > 100:
grade = grade - 100
else:
grade = 0
sum_extra += grade

print('Sum extra:', sum_extra)

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

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.

ACCESS MORE