python
Copy code
# 從鍵盤輸入學生成績
score = int(input("請輸入學生成績:"))
# 使用巢狀 if 判斷成績等級
if score >= 80 and score <= 100:
print("成績等級:優等")
elif score >= 60 and score < 80:
print("成績等級:普通")
elif score >= 0 and score < 60:
print("成績等級:不及格")
else:
print("輸入的成績無效")
當執行這段程式時,它會首先提示用戶輸入一個學生成績。然後,程式會根據輸入的成績,使用巢狀 if 敘述來判斷並輸出該成績對應的等級。如果輸入的成績不在有效範圍內(即不在0到100之間),程式會輸出一條提示信息,指出輸入的成績無效。