輸入一個學生成績,並轉換爲A優秀、B良好、C合格、D不及格的形式,將學生成績打印出來。要求使用assert斷言處理分數不合理的情況。
while True:
try:
score = int(input("請輸入你的成績:"))
assert score >= 0 and score <= 100, "輸入有誤請重新輸入!"
if score >= 90:
print('成績爲:A')
elif score >= 80 and score <= 89:
print('成績爲:B')
elif score >= 60 and score <= 79:
print('成績爲:C')
else:
print('成績爲:D,不及格!!!')
except AssertionError as reason:
print(reason)