After completing the homework, you will submit:
election.py
Hand in your work at this Google Form: https://goo.gl/forms/Fkr461qrsm27iZnP2
An election is happening on Valeria’s planet of Saturn, and she needs help counting the votes (the hanging chads are causing an uproar in the election between Al Blood and George Shrub). Help her ensure a peaceful transition of power!
name_matches
that takes a vote (string) and a name and returns a boolean indicating whether the vote is for the given name, regardless of how the vote and name have been capitalized (that is, ignore case). You can lowercase a string s
in Python by writing s.lower()
(where s
gets replaced by the string you want to lowercase). As in Pyret, you have Boolean operators and
, or
, and not
.any_votes_for
that takes a name and a list of votes and returns a boolean indicating whether any votes were for the given name (case insensitive).count_votes_for
that takes a name and a list of votes and returns the number of votes that were for the given name (case insensitve).got_more_votes
that takes two names and a list of votes, and returns the name that got more votes (case insensitve). If there is a tie, return “Tie”.record_vote
that takes a list of votes and a new vote and adds the vote to the list. This should modify the input list, and not return anything.percentage_votes
that takes a name and a list of votes and returns the percentage of votes that match (case insensitve) the given name. Assume that there is always at least one vote in the list, and you should return the percent in decimal form (i.e. if the name matches 90% of the votes, return 0.9).test_votes
to test your vote functions. In particular, think about how to test record_vote
. Run test_votes()
to make sure all your tests pass and your functions work as expected.Remember that you need to put from testlight import *
in your file to get the testing function from class. There are instructions on getting the testlight
file into the proper directory in the Youtube video below; as usual, any problems and just let the TAs know.