Kodewick
Start learning →
Basic←→0 / 80

Goals per game

#052BasicErrorsDicts5 min

The football team keeps {name: (goals, games)} for each player. Write goals_per_game(record) to return {name: average goals per game}, rounded with round(..., 1). A player who hasn't played yet (games is 0) gets 0.0.

Examples
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():
        # your code here: goals / games rounded to 1 place into result; 0.0 when it divides by 0
        pass
    return result
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.