# traceback_lab.py
# 請直接執行此程式，並根據產生的 Traceback 錯誤逐步進行修復。
# 檢查/送出作業：uv run https://py.candys.page/traceback_lab_checker.py

students = [
    {"name": "Alice", "score": 85},
    {"name": "Bob", "score": "92"},
    {"name": "David", "score": None},
    {"name": "Emma", "score": 95}
]

# 1. 計算總分與有效應考人數（排除缺考的 None，並將字串轉換為整數）
total_score = 0
valid_count = 0
for s in students:
    total_score += s["score"]
    valid_count += 1

average = total_score / valid_count if valid_count > 0 else 0
print(f"有效應考人數：{valid_count} 人")
print(f"平均分數：{average:.2f} 分")

# 2. 找出最高分的學生（排除缺考的 None）
highest_student = students[0]
for s in students:
    if s["score"] > highest_student["score"]:
        highest_student = s

print(f"最高分學生：{highest_student['name']} ({highest_student['score']} 分)")
