Commit 2727c49c authored by Adam Blank's avatar Adam Blank
Browse files

Add new file

parent 1ca63891
Showing with 73 additions and 0 deletions
+73 -0
import math
def process_votes() -> tuple[dict[str, list[str]], str | None]:
"""
Takes in votes from the voters, and processes the winner.
Returns:
dict[str, list[str]]: A dictionary where the keys are the possible
options someone could vote for. The value associated with each option
is a list of people who voted for that option.
"""
vote_tracker: dict[str, list[str]] = {}
done: bool = False
while ...:
name: str = input("What is your name? ")
choice: str = input("Hi there " + name + ". Which ice cream flavor is your favorite? ")
...
more_votes: str = input("Your vote has been registered. Are there more votes to process? Y/N ")
if more_votes == "N":
done = True
#Determine the winning option
max_votes = ...
winning_option = ...
for option in vote_tracker:
num_votes = ...
if ...:
max_votes = ...
winning_option = ...
return (vote_tracker, winning_option)
# results = process_votes()
# print(votes[0])
# print(votes[1])
def highest_vote_count(vote_tracker: dict[str, list[str]]) -> str | None:
"""
Identifies the person who voted the most times across all options.
Args:
vote_tracker (dict[str, list[str]]): A dictionary where the keys are
the possible options someone could vote for. The value associated
with each option is a list of people who voted for that option.
Returns:
str: The name of the person who appears most frequently across all
voting lists. If there's a tie, one of the top voters is returned
arbitrarily.
"""
vote_counter: dict[str, int] = {}
for voters in vote_tracker.values():
for person in voters:
if person in vote_counter:
vote_counter[person] += 1
else:
vote_counter[person] = 1
max_votes = -math.inf
top_voter = None
for person in vote_counter:
if vote_counter[person] > max_votes:
max_votes = vote_counter[person]
top_voter = person
return top_voter
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment