返回列表 發帖

if...elif...else

多向判斷式語法
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("輸入錯誤!")
複製代碼

elif score>=70 and score<80:
    print("乙等!")
elif score>=60 and score<70:
    print("丙等!")
elif score>=0 and score<60:
    print("不及格!")
else:
    print("輸入錯誤!")

TOP

a=int(input("請輸入你的成績:"))
if a>=90 and a<=100:
    print("優等!")
elif a>=80 and a<90:
    print("甲等!")
elif a>=70 and a<80:
    print("乙等!")
elif a>=60 and a<70:            
    print("丙等!")
elif a>=0 and a<60:
    print("不及格!")
eles:
  print("輸入錯誤!")

TOP

  1. a=float(input("enter Chinese 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("輸入錯誤")
複製代碼

TOP

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

TOP

  1. a=int(input("請輸入國文成績: "))
  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("輸入錯!")   
複製代碼

TOP

本帖最後由 李品蓁 於 2024-1-25 09:03 編輯
  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=float(input("enter Chinese score"))
  2. if(a=100):
  3.     print("優")
  4. elif
  5.     print("甲")
  6. elif
  7.     print("乙")
  8. elif
  9.     print("丙")
  10. elif
  11.     print("不及格")
  12. else:
  13.     print("輸入錯誤")
複製代碼

TOP

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

  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("乙等")   
複製代碼

TOP

  1. a=int(input("國文成績"))
  2. if a>=90 and a<=100:
  3.     print("優等")
  4. elif a>=80 and a<=89:
  5.     print("甲等")
  6. elif a>=70 and a<=79:
  7.     print("乙等")
  8. elif a>=60 and a<=69:
  9.     print("丙等")
  10. elif a>=0 and a<=60:
  11.     print("不及格")
  12. else:
  13.     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>=60,a<=100):
  3.     print("及格了")
  4. elif(a<60,a>=0):
  5.     print("沒及格")
  6. else:
  7.     print("Error:input_failure")
複製代碼

TOP

返回列表