Question: Function name: election_day Parameters: a nested list; each list will contain three values: the first value will be the name of a candidate (str), the
Function name: election_day Parameters: a nested list; each list will contain three values: the first value will be the name of a candidate (str), the second value will be the total number of votes this candidate received (int) , and the third parameter will be the two-letter abbreviation of a U.S. state (str). Return value: a string representation of the winning candidate, the total number of votes the candidate received, and the state in which the candidate received the most votes Description: You are helping total the votes for a nationwide political election. Write a function that returns a string with the name of the winning candidate (i.e. the candidate who received the highest total number of votes across all states), the total number of votes for that candidate, and the state in which the candidate received the most votes. If two candidates are tied for highest number of votes, your function should return information for the candidate that appears first in the list.
Note: Failing to return the exact format of the string will cause you to lose points. (Format: Candidate name[comma][space] total # of votes [comma][space] two-letter state abbreviation)
Test Cases:
>>> election_1 = [["Pepsi", 500, "CA"], ["Coke", 15000, "GA"], ["Pepsi", 3, "GA"], ["Dr. Pepper", 1000, "WY"], ["Coke", 100, "WI"]] >>> results_1 = election_day(election_1)
>>> print(results_1) Coke, 15100, GA
>>> election_2 = [["cats", 150, "HI"], ["dogs", 30, "NJ"], ["dogs", 80, "AZ"], ["fish", 300, "FL"], ["cats", 50, "PA"], ["dogs", 190, "HI"], ["cats", 25, "WA"], ["cats", 75, "RI"]] >>> results_2 = election_day(election_2)
>>> print(results_2) cats, 300, HI
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
