Kodewick
開始學 →
基礎←→0 / 80

每場進幾球

#052基礎for name, (g, n) in .items()約 5 分鐘

足球隊記著每個隊員的 (進球, 場數):{名字: (進球, 場數)}。寫 goals_per_game(record),返回 {名字: 平均每場進球},用 round(..., 1) 保留一位小數。還沒上過場的(場數是 0)算 0.0。

示例
goals_per_game({"Mia": (10, 3), "Leo": (2, 0)})→{'Mia': 3.3, 'Leo': 0.0}
goals_per_game({})→{}
main.py
def goals_per_game(record):
    result = {}
    for name, (goals, games) in record.items():
        # 在這裡寫:算 goals / games 保留一位小數放進 result;除以 0 時放 0.0
        pass
    return result
Ctrl + Enter 也能執行
結果

寫好了先點「執行」試試示例,沒問題再點「提交」。