Contents ...
udn網路城邦
python範例程式(二)
2025/10/18 12:00
瀏覽33
迴響0
推薦0
引用0
# ==============================

# 🧮 成績等第判斷系統

# 輸入多科成績,依分數輸出等第 A~J

# ==============================


# 定義科目清單(List)

subjects = ["chinese", "english", "math", "nature", "history"]


# 使用 for 迴圈依序讀取每一個科目

for subject in subjects:

    # 要求使用者輸入該科目的分數

    grades = int(input(f"請輸入 {subject} 的成績: "))


    # 以下為成績等第對照表

    # 根據輸入的分數判斷對應的等第(A~J)


    if grades > 89 and grades < 101:  # 90 ~ 100 分

        print("A")

    elif grades > 79 and grades < 90:  # 80 ~ 89 分

        print("B")

    elif grades > 69 and grades < 80:  # 70 ~ 79 分

        print("C")

    elif grades > 59 and grades < 70:  # 60 ~ 69 分

        print("D")

    elif grades > 49 and grades < 60:  # 50 ~ 59 分

        print("E")

    elif grades > 39 and grades < 50:  # 40 ~ 49 分

        print("F")

    elif grades > 29 and grades < 40:  # 30 ~ 39 分

        print("G")

    elif grades > 19 and grades < 30:  # 20 ~ 29 分

        print("H")

    elif grades > 9 and grades < 20:   # 10 ~ 19 分

        print("I")

    else:                              # 0 ~ 9 分 或 無效輸入

        print("J")
你可能會有興趣的文章:

限會員,要發表迴響,請先登入