怎么优化啊?
while True:yuan = input("请输入分值:")
yuan = int(yuan)
if 0 <= yuan < 60 :
print ("D")
else:
if 60 <= yuan <80:
print("C")
else:
if 80 <= yuan <90:
print("B")
else:
if 90 <= yuan <100:
print("A")
else:
if yuan == 100:
print("S")
else:
if yuan > 100:
print("请输入0到100的分值")
answer = input("是否继续:")
if answer == "退出":
break
本帖最后由 Twilight6 于 2020-7-26 13:21 编辑
用 elif ,应该你还没学习到,不过你继续看下去,马上就会学习到的
elif :只要前面的 if 或者 elif 成立一次,后续的 elif 就不会再次进行判断
while True:
yuan = input("请输入分值:")
yuan = int(yuan)
if 0 <= yuan < 60 :
print ("D")
elif 60 <= yuan <80:
print("C")
elif 80 <= yuan <90:
print("B")
elif 90 <= yuan <100:
print("A")
elif yuan == 100:
print("S")
else:
print("请输入0到100的分值")
answer = input("是否继续:")
if answer == "退出":
break
页:
[1]