正经解决问题的回答:
分三次try except
def get_input(hint_text):
while 1:
try:return eval(input(hint_text))
except:pass
A=get_input("A班: ")
B=get_input("B班: ")
C=get_input("C班: ")
另外尽量不要使用eval, 想要获得整数或浮点数使用int,float, 获取字符串的话直接input就行了
代码写的比较简陋,见谅
添加筛选条件
def get_input(hint_text, max=None, min=None):
while 1:
try:
result=float(input(hint_text))
if (max and maxresult):
print('Bad Value')
continue
return result
except:pass
a=get_input('A班', 0, 100)