返回列表 發帖

if...elif...else

本帖最後由 tonyh 於 2022-1-27 10:04 編輯

  1. score=input("請輸入你的成績: ")
  2. score=float(score)
  3. if score>100:
  4.     print("輸入錯誤~斬!")
  5. elif score>=90:
  6.     print("優")  
  7. elif score>=80:
  8.     print("甲")
  9. elif score>=70:
  10.     print("乙")
  11. elif score>=60:
  12.     print("丙")
  13. elif score>=0:
  14.     print("不及格")
  15. else:
  16.     print("輸入錯誤~斬!")
複製代碼
  1. score=input("請輸入你的成績: ")
  2. score=float(score)
  3. if score>=90 and score<=100:  #多擇一
  4.     print("優")
  5. elif score>=80 and score<90:
  6.     print("甲")
  7. elif score>=70 and score<80:
  8.     print("乙")
  9. elif score>=60 and score<70:
  10.     print("丙")
  11. elif score>=0 and score<60:
  12.     print("不及格")
  13. else:
  14.     print("輸入錯誤~斬!")
複製代碼
  1. score=input("請輸入你的成績: ")
  2. score=float(score)
  3. if(score>=90 and score<=100):
  4.     print("優等!")
  5. elif(score>=80 and score<90):
  6.     print("甲等!")
  7. elif(score>=70 and score<80):
  8.     print("乙等!")
  9. elif(score>=60 and score<70):
  10.     print("丙等!")
  11. elif(score>=0 and score<60):
  12.     print("不及格!")
  13. else:
  14.     print("輸入錯誤!")
複製代碼

返回列表