Board logo

標題: if...elif...else [打印本頁]

作者: tonyh    時間: 2022-3-26 15:31     標題: 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("輸入錯誤!")
複製代碼

作者: 郭詩瑜    時間: 2022-3-26 16:14

  1. score = float(input("Input Score: "))
  2. if (90 <= score <= 100):
  3.     print("A++")
  4. elif (score >90<=80):
  5.     print("A+")
  6. elif (score >80<=70):
  7.     print("A")
  8. elif (score >70<=60):
  9.     print("B")
  10. elif (score <60>=0):
  11.     print("C")
  12. else:
  13.     print("Failed")
複製代碼

作者: 郭詩瑜    時間: 2022-3-26 16:28

  1. score = float(input("Input Score: "))
  2. if (score < 0 or score > 100):
  3.     print("Failed")
  4. elif (score >= 90):
  5.     print("A++")
  6. elif (score >= 80):
  7.     print("A+")
  8. elif (score >= 70):
  9.     print("A")
  10. elif (score >= 60):
  11.     print("B")
  12. else:
  13.     print("C")
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2