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

x
x

sum
sum

temp
temp

grade

1 answer

To debug the program and find out why the average is not printing out correctly, the most appropriate variable to print out is sum.

Here is why:

  • The variable temp correctly stores each individual grade input, but it does not directly contribute to the final average calculation in the way intended.
  • The variable x is just looping through a range and won't help you understand the accumulated sum.
  • The variable grade will give you the final output, but if the sum is incorrect, then grade will also be incorrect.

The issue in your code arises from this line:

sum = temp + 1

This line is incorrectly adding 1 to temp instead of accumulating the grades together.

So, printing sum would help you identify that the accumulated sum is incorrect, while your calculation for the average is based on that incorrect sum.