Search code examples
pythoncalculatoreasygui

Grade Calculator isn't exiting


I have a program that is supposed to approximate a letter grade based off of an integer input. I want it to be able to run continuously until the number "-1" is input, then quit. However, whenever I try to run it, the program just keeps telling me my grade over and over again, and it won't do anything else. Here is what I have so far.

import easygui


grade = int(easygui.enterbox(msg="Enter a grade between 0 and 100: "))
while grade != -1:

    if grade >= 90 and grade <100:
        easygui.msgbox ("You got an A")
    if grade >= 80 and grade <90:
        easygui.msgbox ("You got a B")
    if grade >= 70 and grade <80:
        easygui.msgbox ("You got a C")
    if grade >= 60 and grade <70:
        easygui.msgbox ("You got a D")
    if grade >= 0 and grade <60:
        easygui.msgbox ("You got an F")

else: raise SystemExit

Solution

  • You need to take the inputted grade again in while loop.

        import easygui
    
    
    grade = int(easygui.enterbox(msg="Enter a grade between 0 and 100: "))
    while grade != -1:
    
        if grade >= 90 and grade <100:
            easygui.msgbox ("You got an A")
        if grade >= 80 and grade <90:
            easygui.msgbox ("You got a B")
        if grade >= 70 and grade <80:
            easygui.msgbox ("You got a C")
        if grade >= 60 and grade <70:
            easygui.msgbox ("You got a D")
        if grade >= 0 and grade <60:
            easygui.msgbox ("You got an F")
    
        grade = int(easygui.enterbox(msg="Enter a grade between 0 and 100: "))
    
    else: raise SystemExit