程式碼檢視器 – 2-2-score-average-if-else-print-get_score.py

← 返回清單
# -*- coding: utf-8 -*-

def get_score(subject):
    """要求使用者輸入成績,並檢查有效性"""
    while True:
        try:
            value = int(input(f"{subject}成績:"))
            if 0 <= value <= 100:
                return value
            else:
                print("⚠️ 請輸入 0 ~ 100 之間的數字")
        except ValueError:
            print("⚠️ 請輸入有效的數字")

print("請依序輸入三科成績:國文、英文、數學")

score_a = get_score("國文")
score_b = get_score("英文")
score_c = get_score("數學")

total = score_a + score_b + score_c
average = total / 3.0

print("\n三科總分:", total)
print("平均分數:", round(average, 2), "分")

PASS_THRESHOLD = 80
if average >= PASS_THRESHOLD:
    print("恭喜!平均分數達到標準,表現很優秀!")
else:
    print("加油!尚未達到標準,下次一定可以更好!")