返回列表 發帖

if...elif...else

本帖最後由 tonyh 於 2022-3-26 16:19 編輯

  1. score=float(input("請輸入你的成績: "))
  2. if score>100 or score<0:
  3.     print("輸入錯誤")
  4. elif score>=90:
  5.     print("優")
  6. elif score>=80:
  7.     print("甲")
  8. elif score>=70:
  9.     print("乙")
  10. elif score>=60:
  11.     print("丙")
  12. else:
  13.     print("不及格")  
複製代碼
  1. score=float(input("請輸入你的成績: "))
  2. if 90<=score<=100:
  3.     print("優")
  4. elif 80<=score<90:
  5.     print("甲")
  6. elif 70<=score<80:
  7.     print("乙")
  8. elif 60<=score<70:
  9.     print("丙")
  10. elif 0<=score<60:
  11.     print("不及格")
  12. else:
  13.     print("輸入錯誤")
複製代碼
  1. score=float(input("請輸入你的成績: "))
  2. if score>=90<=100:
  3.     print("優")
  4. elif score>=80<90:
  5.     print("甲")
  6. elif score>=70<80:
  7.     print("乙")
  8. elif score>=60<70:
  9.     print("丙")
  10. elif score>=0<60:
  11.     print("不及格")
  12. else:
  13.     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("輸入錯誤!")
複製代碼

返回列表