返回列表 發帖

if...elif...else

本帖最後由 鄭繼威 於 2023-7-10 15:51 編輯

多向判斷式語法
if (條件式一) :
    程式區塊一
elif (條件式二):
    程式區塊二
elif (條件式三):
    程式區塊三
.........
else:
    else的程式區塊


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

hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi

TOP

  1. score=input("輸入成績:")
  2. score=int(score)
  3. if score==100:
  4.     print("優等")
  5. elif score>=90 and score<99:
  6.     print("甲等!")
  7. elif score>=80 and score<89:
  8.     print("乙等!")
  9. elif score>=70 and score<79:
  10.     print("丙等!")
  11. elif score>=60 and score<69:
  12.     print("丁等!")
  13. elif score>=0 and score<59:
  14.     print("不及格!")
  15. else:
  16.     print("輸入錯誤")
複製代碼

TOP

本帖最後由 歐陽霖 於 2023-7-10 21:14 編輯
  1. englishscore=int(input("請輸入英文成績:"))
  2. chinesescore=int(input("請輸入國文成績:"))
  3. mathscore=int(input("請輸入數學成績:"))
  4. totalscore=englishscore+chinesescore+mathscore
  5. print("總分:",totalscore)
  6. totalscore=totalscore/3
  7. print("平均分數為%.2f"%totalscore)
  8. if totalscore==100:
  9.     print("優等!!")
  10. elif totalscore>=90 and totalscore<100:
  11.     print("甲等!!")
  12. elif totalscore>=80 and totalscore<90:
  13.     print("乙等!!")
  14. elif totalscore>=70 and totalscore<80:
  15.     print("丙等!!")
  16. elif totalscore>=60 and totalscore<70:
  17.     print("丁等!!")
  18. elif totalscore>=0 and totalscore<60:
  19.     print("不及格!!")
  20. else:
  21.     print("輸入錯誤!!")
複製代碼

TOP

總分=input("輸入成績:")
if 總分>60:
    print("及格")
else:
    print("不及格")

TOP

  1. k=input("Please enter Chinese score: ")
  2. l=input("Please enter Math score: ")
  3. m=input("Please enter English score: ")
  4. print("Total= "+str(int(k)+int(l)+int(m)))
  5. n=(int(k)+int(l)+int(m))/3
  6. o="Average= %.2f"%n
  7. print(o)
  8. if float(o) or int(o)==100:
  9.     print("Excellent!")
  10. elif:(float(o) or int(o) >=90) and (float(o) or int(o)<=99):
  11.     print("Great!")
  12. elif:float(o) or int(o) >=80 and float(o) or int(o)<=89:
  13.     print("Awesome!")
  14. elif:float(o) or int(o) >=70 and float(o) or int(o)<=79:
  15.     print("Good!")
  16. elif:float(o) or int(o) >=60 and float(o) or int(o)<=69:
  17.     print("It's ok!")
  18. elif:float(o) or int(o) >=0 and float(o) or int(o)<=59:
  19.     print("You can o it better!")
  20. else:
  21.     print("You're wrong!")
複製代碼
(有Bug)

TOP

  1. a=int(input("輸入你的成績:"))
  2. if a>=90 and a<=100:
  3.     print("優等")
  4. elif a>=80 and a<90:
  5.    
  6.     print("甲等")
  7. elif a>=70 and a<80:
  8.     print("乙等")
  9. elif a>=60 and a<70:
  10.     print("丙等")
  11. elif a>=0 and a<60:
  12.     print("不及格")
  13. else:
  14.     print("輸入已成績高於最大值")
複製代碼

TOP

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

TOP

  1. a=int(input("請輸入成績:"))
  2. if a==100:
  3.     print("優等")
  4. elif a>=90 and a<=99:
  5.     print("甲等")
  6. elif a>=80 and a<=89:
  7.     print("等")
  8. elif a>=70 and a<=79:
  9.     print("丙等")
  10. elif a>=60 and a<=69:
  11.     print("丁等")
  12. elif a>=0 and a<=59:
  13.     print("不及格")

  14. else:
  15.     print("錯誤")
複製代碼

TOP

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

TOP

  1. score=int(input("請輸入你的成績: "))
  2. if score==100:
  3.     print("優等")
  4. elif score>=90 and score<=99:
  5.     print("甲等")
  6. elif score>=80 and score<=89:
  7.     print("乙等")
  8. elif score>=70 and score<=79:
  9.     print("丙等")
  10. elif score>=60 and score<=69:
  11.     print("丁等")
  12. elif score<60:
  13.     print("不及格")
  14. else:
  15.     print("輸入錯誤")
複製代碼

TOP

  1. a=int(input("What's your score?"))
  2. if a>=90 and a<=100:
  3.     print("優等")
  4.     elif a>=80 and a<90:
  5.     print("甲等")
  6.     elif a>=70 and a<80:
  7.     print("乙等")
  8.     elif a>=60 and a<70:
  9.     print("丙等")
  10.     elif a>=0 and a<60:
  11.     print("不及格")
  12. else:
  13.     print("what are you high on cuz i want some")
複製代碼
Attention Seeker </3

TOP

6

TOP

  1. score=int(input("請輸入成績:"))
  2. if score==100:
  3.     print("特優!!")
  4. elif score>=90 and score<=99:
  5.     print("優等")
  6. elif score>=80 and score<=89:
  7.     print("甲等")
  8. elif score>=70 and score<=79:
  9.     print("乙等")
  10. elif score>=60 and score<=69:
  11.     print("丙等")
  12. elif score>=0 and score<=59:
  13.     print("丁等")   
  14. else:
  15.     print("錯誤")
複製代碼

TOP

  1. score=input("請輸入你的成績:")
  2. score=int(score)

  3. if score==100:
  4.     print("優等")
  5.    
  6. elif score>=90 and score<=99:
  7.     print("甲等")
  8.    
  9. elif score>=80 and score<=89:
  10.     print("乙等")
  11.    
  12. elif score>=70 and score<=79:
  13.     print("丙等")
  14.    
  15. elif score>=60 and score<=69:
  16.     print("丁等")
  17.    
  18. else:
  19.     print("輸入錯誤")
複製代碼

TOP

  1. score=int(input("請輸入成績:")            
  2. if score==100
  3.      print("優等")
  4. elif score>=90 and score<=99:
  5.     print("甲")
  6. elif score>=80 and score<=89  
  7.      print("乙")
  8. elif score>=70 and score<=79   
  9.      print("丙")
  10. elif score>=60 and score<=69  
  11.      print("丁")
  12. elif score>=0 and score<=59
  13.      print("不及格")
  14. elso score>100 and score<0   
  15.      print("1-100以外")
  16.      
複製代碼

TOP

  1. name=input("請輸入姓名:")
  2. score=int(int("請輸入成績:"))
  3. if  score==100:
  4.     print(f"{name} 你是天才!IQ180")
  5. elif score>=90 and score<=99:
  6.     print(f"{name} 你是甲等")
  7. elif score>=80 and score<=89:
  8.     print(f"{name} 你是乙等")
  9. elif score>=70 and score<=79:
  10.     print(f"{name} 你是丙等")
  11. elif score>=60 and score<=69:
  12.     print(f"{name} 你是丁等")
  13. elif score>=0 and score<=59:
  14.     print(f"{name}!你不及格!滾!")
  15. else:
  16.     print(f"{name}!你的成績輸入錯誤")
複製代碼

TOP

a=int(input("成績="))
if a<=100 and a>=90:
    print("you")
   
elif a<=89 and a>=80:
    print("jia")

elif a<=79 and a>=70:
    print("乙等")
   
elif a<=69 and a>=60:
    print("丙等")
   
elif a<=59 and a>=0:
    print("不及格")
   
else:
    print("輸入錯誤")

TOP

返回列表