等级计算器不会退出

时间:2016-03-14 22:00:18

标签: python calculator easygui

我有一个程序应该基于整数输入来近似字母等级。我希望它能够持续运行,直到#34; -1"输入,然后退出。但是,每当我尝试运行它时,程序就会一遍又一遍地告诉我我的成绩,并且它不会做任何其他事情。这是我到目前为止所拥有的。

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

2 个答案:

答案 0 :(得分:1)

你需要在while循环中再次输入输入的等级。

    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

答案 1 :(得分:0)

import easygui

grade = int(easygui.enterbox(msg =&#34;输入0到100之间的等级:&#34;)) 等级!= -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:提升SystemExit