To debug the program effectively, the most appropriate variable to print out would be sum
.
The issue lies in the line sum = temp + 1
, which incorrectly calculates the sum of grades by always adding 1 to the grade entered instead of accumulating the total. Printing sum
after the loop will help determine if it is being calculated correctly. Here’s how the relevant part of the code would look with added debug output:
sum = 0
for x in range(0, 5):
temp = float(input("Grade: "))
sum = sum + temp # Correct way to add the grade to the total
print("Current sum: ", sum) # Debug output
This way, you can see the sum
after all grades are entered and identify if it matches your expectation.