Exemple #1
0
def tally_team_medals(data):
    tui.started("Tallying results for each team"
                )  # Calls function 'started()' with a message

    team_tally = {}  # Creates empty dictionary 'team_tally'

    for record in data:  # For each record (line) in the data
        team_name = record[
            teams_from_data]  # Variable 'team_name' to store the name data from the record[position]
        medal = record[
            medals_from_data]  # Variable 'medal' to store the name data from the record[position]

        if medal not in (
                "Gold", "Silver",
                "Bronze"):  # If no 'Gold', 'Silver' or 'Bronze' in medal
            continue  # Continue to next line

        if team_name in team_tally:  # If the team name is already in 'team_tally'
            team_tally[team_name][
                medal] += 1  # Retrieve the nested medals dictionary for that team and increment the count
        else:
            team_tally[team_name] = {
                "Gold": 0,
                "Silver": 0,
                "Bronze": 0
            }  # Create the [medal] dictionary
            team_tally[team_name][medal] += 1  # And increment the count

    tui.display_medal_tally(team_tally)  # Calls display function
    tui.completed()  # Calls function 'completed()' from tui file
Exemple #2
0
def tally_medals(data):
    tui.started("Tallying medals")
    medal_tally = {"Gold": 0, "Silver": 0, "Bronze": 0}
    for record in data:
        medal = record[14]
        if medal in ("Gold", "Silver", "Bronze"):
            medal_tally[medal] += 1
    tui.display_medal_tally(medal_tally)
    tui.completed()
Exemple #3
0
def tally_medals(data):
    tui.started("Tallying medals")
    medals_tally = {"Gold: 0", "Silver: 0," "Bronze: 0"}
    # The function should iterate through each record in the list data and extract the medal.
    # If the medal is "Gold", "Silver" or "Bronze" then the relevant count in the dictionary should be incremented.
    for record in data:
        medal = record[col_medal]
        if medal in ("Gold", "Silver", "Bronze"):
            medals_tally[medal] += 1
    # The dictionary should contain the total count of each medal once the code has finished iterating through the
    # list data. The appropriate functions from the module tui should be called to indicate the start of the
    # operation, display the tally of medals and indicate the end of the operation.
    tui.display_medal_tally(medals_tally)
    tui.completed()
Exemple #4
0
def tally_medals(data):
    tui.started("Tallying medals...")
    medals = {"Gold": 0, "Silver": 0, "Bronze": 0}


    for records in data:
        if records[14] == "Gold":
            medals['Gold'] += 1
        elif records[14] == "Silver":
            medals['Silver'] += 1
        elif records[14] == "Bronze":
            medals['Bronze'] += 1

    tui.display_medal_tally(medals)
    tui.completed()
Exemple #5
0
def tally_medals(data):
    tui.started(
        "Tallying medals...")  # Calls function 'started()' with a message

    tally = {
        "Gold": 0,
        "Silver": 0,
        "Bronze": 0
    }  # Creates a dictionary called 'tally'

    for record in data:  # For each record (line) in the data
        medal = record[
            medals_from_data]  # Variable to store each medal (the record from [medals_from_data] column 14)
        if medal in (
                "Gold", "Silver", "Bronze"
        ):  # If the content is one of these keys... Gold, Silver, Bronze
            tally[medal] += 1  # Add one to the tally for that medal type

    tui.display_medal_tally(tally)  # Calls the display function
    tui.completed()  # Calls function 'completed()'