The following program is supposed to find the average of five grades.

1 sum = 0
2 for x in range(0,5):
3 temp = float(input("Grade: "))
4 sum = temp + 1
5
6 grade = sum / 5
7 print("Grade = " + str(grade))
But the average is not printing out correctly. A sample run looks as given below.

Grade:

100

Grade:

67

Grade:

89

Grade:

92

Grade:

81

Grade = 16.4



** Process exited - Return Code: 0 **

Press Enter to exit terminal

To find the error which variable would be most appropriate to print out to debug the program?
(1 point)
Responses

temp
temp

sum
sum

grade
grade

x

1 answer

To debug the program and find out why the average grade is not printing out correctly, the most appropriate variable to print would be:

sum

The reason for this choice is that sum is the variable that is being calculated to find the total of the grades entered. In the code, the issue arises from the line:

sum = temp + 1

This line incorrectly adds 1 to the current grade input (temp) instead of adding it to the cumulative sum of the grades. Printing sum after the loop will show whether it has been calculated correctly or not. By examining its value, you can determine if the error is due to the logic in accumulating grades.