修改代码
我想将用户输入的分数限制在(1,100)的范围内,其余的输如均为无效数据应该什么修改代码呀? score = int(input("请输入您的分数:"))while score in range(1,101):
if:
if:
if:
else:
print °蓝鲤歌蓝 发表于 2017-12-15 17:55
谢谢,我想到了加范围限制就是不知道怎么加,加在那个位置。要学的还很多啊啊啊啊 if score>100 or score<1:
print("数据无效") 本帖最后由 215330 于 2017-12-15 18:12 编辑
°蓝鲤歌蓝 发表于 2017-12-15 17:55
666
if 0<=score<60:
elif 60<=score<80:
elif 80<=score<90:
elif 90<=score<=100:
else:
print("输入无效") ba21 发表于 2017-12-15 18:16
谢谢老铁! 本帖最后由 215330 于 2017-12-15 18:28 编辑
score = int (input("请输入您的分数:"))
if score>100 or score<1:
print("数据无效")
if 0<=score<60:
print("D")
if 60<=score<80:
print("C")
if 80<=score<90:
print("B")
if 90<=score<=100:
print("A")
最后的代码是这样的,满足了我想要的了。谢谢楼上俩老铁
try:
score = int(input('请输入您的分数'))
except (ValueError, EOFError, KeyboardInterrupt):
print('输入错误!')
if 60 <= score < 80:
print("C")
elif 80 <= score < 90:
print("B")
elif 90 <= score < 100:
print("A")
elif 60 > score:
print("D")
else:
print('输入错误!')
页:
[1]