2016-03-14 33 views
0

我有一个程序,应该基于一个整数输入来估计字母等级。我希望它能够连续运行,直到输入数字“-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 

回答

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 
+0

虽然增加了取消按钮,但我的问题仍然没有解决。我希望它一直运行,只要它告诉我它会提示另一个的级别。谢谢你。 – TheSwune

+0

它适合我。所以你甚至不需要看取消按钮。你继续输入值。它会给你你的成绩。当你输入-1时,它将被关闭。 –

+0

你是在Python 2还是3?我正在运行2.7,它不工作 – TheSwune

0
import easygui 

级= INT(easygui.enterbox(味精= “输入一个0级和100之间:”))! 而等级= -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: ")) 

其他:加薪SystemExit