f = input('Enter score:')
try:
f=float(f)
if f<0 or f>1:
print('Error data1')
elif f>=0.9:
print('A')
elif f>=0.8:
print('B')
elif f>=0.7:
print('C')
elif f>=0.6:
print('D')
else:
print('F')
except:
print('Error data')
这里的输入始终是Error data, 是因为在try下面用if了导致第一个f<0 or f>1判断不过导致直接进行except下的程序么
以及为啥改成
try:
f = input('Enter score:')
就可以正常判断了。
谢谢!救救孩子= =