Creating a Test and Debug Plan Quick Check 5 of 55 of 5 Items Question Suppose you are writing a program to convert numeric grades to letter grades: print("Enter numeric grade: ") avg = int(input()) if avg >= 90 and avg <= 100: print("Your Grade is A") if avg >= 80 and avg < 90: print("Your Grade is B") if avg >= 70 and avg < 80: print("Your Grade is C") if avg >= 60 and avg < 70: print("Your Grade is D") if avg >= 0 and avg < 70: print("Your Grade is F") if avg < 0 or avg > 100: print("Invalid Input!") When you test the program for the value 65, you get the following output: Enter numeric grade: 65 Your Grade is D Your Grade is F ** Process exited - Return Code: 0 ** Press Enter to exit terminal How can you locate the error? (1 point) Responses Use other data points, and see if they work. Use other data points, and see if they work. Use a trace tool to go line by line and see how the program is progressing. Use a trace tool to go line by line and see how the program is progressing. Use print statements, so you can locate the error. Use print statements, so you can locate the error. Use a different editor, and see if that fixes the problem. Use a different editor, and see if that fixes the problem. Skip to navigation page 5 of 5

1 answer

To locate the error in your program, the most effective approach is:

Use print statements, so you can locate the error.

This option allows you to examine which conditions are being met and to check the flow of the program as it evaluates each conditional. By adding print statements before each conditional check, you can see the values being evaluated and determine why both "Your Grade is D" and "Your Grade is F" are being printed for the input of 65.

In this specific case, the issue arises from the fact that the conditions are not mutually exclusive, and as a result, multiple conditions may be evaluated as true. The correct condition for grading should use elif (else if) statements to prevent subsequent conditions from being evaluated once a true condition is found. Here's a revised version of your grading code:

print("Enter numeric grade: ") 
avg = int(input())
if avg >= 90 and avg <= 100:
    print("Your Grade is A") 
elif avg >= 80 and avg < 90: 
    print("Your Grade is B") 
elif avg >= 70 and avg < 80: 
    print("Your Grade is C") 
elif avg >= 60 and avg < 70: 
    print("Your Grade is D") 
elif avg >= 0 and avg < 60: 
    print("Your Grade is F") 
elif avg < 0 or avg > 100: 
    print("Invalid Input!")

This structure will ensure that only the first matching grade condition will execute.