Commit ff065e5d authored by Jedidiah Tsang's avatar Jedidiah Tsang
Browse files

Add lecture code

parent 1eceb5b5
No related merge requests found
Showing with 43 additions and 1 deletion
+43 -1
import math
from collections import Counter
def process_votes() -> tuple[Counter, str | None]:
"""
Takes in votes from the voters, and processes the winner.
Returns:
tuple[Counter, str | None]: A Counter where the keys are the possible
options someone could vote for. The value associated with each option
is the number of people who voted for that option.
"""
vote_tracker = {}
#Solicit votes
done: bool = False
while not done:
choice: str = input("Hi there. Which ice cream flavor is your favorite? ").lower()
if choice not in vote_tracker:
vote_tracker[choice] = 0
vote_tracker[choice] += 1
more_votes: str = input("Your vote has been registered. Are there more votes to process? Y/N ").upper()
if more_votes == "N":
done = True
#Determine the winning option
max_votes = -math.inf
winning_option = None
for option in vote_tracker:
num_votes = vote_tracker[option]
if num_votes > max_votes:
max_votes = num_votes
winning_option = option
return (vote_tracker, winning_option)
results = process_votes()
if results[1] != None:
print("The winning option is...", results[1] + "!!!!!")
......@@ -4,7 +4,8 @@
"00/experimenting.py",
"00/main.py",
"12/physics.py",
"13/monty.py"
"13/monty.py",
"16/vote_counter.py"
],
"ignore": []
}
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