Due: Tuesday November 12, 2019 at 9:00PM EST.
After completing the homework, you will submit:
Because all we need are the files, you do not need to submit the whole project folder. As long as the file you create has the same name as what needs to be submitted, you’re good to go!
If you are using late days, make sure to make a note of that in your readme. Remember, you may only use a maximum of 3 late days per assignment. If the assignment is late (and you do NOT have anymore late days) no credit will be given.
You can round a number in Python using the
round function. The
round function has two arguments, the first being the number to round and the second representing how many decimal places to have. Here are a few examples:
# If you'd like to round to the nearest whole number # Note: this will still produce a decimal not an Int round(1.3446, 0) # produces 1.0 round(1.5111, 0) # produces 2.0 round(1.7934, 0) # produces 2.0 # If you'd like to round to the nearest tenth round(1.3446, 1) # produces 1.3 round(1.5111, 1) # produces 1.5 round(1.7934, 1) # produces 1.8 # If you'd like to round to the nearest hundreth round(1.3446, 2) # produces 1.34 round(1.5111, 2) # produces 1.51 round(1.7934, 2) # produces 1.79 round(1.799, 2) # produces 1.8
Write your solution for this file in
election.py. Check out this how to get started document on how to create files and write simple scripts.
An election is happening in the Kanto region, and Detective Pikachu needs help counting the votes (Bulbasaur and Charmander are making a mess in the election between Al Blood and George Shrub). Help Detective Pikachu ensure a peaceful transition of power!
name_matchesthat takes a
vote(string) and a
name(string) 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
sin Python by writing
sgets replaced by the string you want to lowercase). As in Pyret, you have Boolean operators
any_votes_forthat takes a
name(string) and a
votes, a list of votes, and returns a boolean indicating whether any votes were for the given name (case insensitive).
count_votes_forthat takes a
name(string) and a
votes, a list of votes, and returns the number of votes that were for the given name (case insensitve).
got_more_votesthat takes two names,
votes, a list of votes, and returns the name that got more votes (case insensitve). If there is a tie, return the string
record_votethat takes in
votes, a list of votes, and
new_vote, a new vote, and adds the vote to the end of the list.
percentage_votesthat takes a name and a list of votes and returns the percentage of votes that match (case insensitve) the given name. You should return the percent in decimal form (i.e. if the name matches 90% of the votes, return 0.9). Please round to the nearest tenth. Don’t forget to consider the case where someone has no votes (or where there are no votes)!
test_votesto test your vote functions. In particular, think about how to test
test_votes()to make sure all your tests pass and your functions work as expected.
Any time you are returning a name, it may be returned lowercased or uppercased. Our test suite is case insensitive, so returning
"Jennifer" will be treated the same as
"JENNIFER". Same applies for functions that return lists.
["Jen","Jennifer"] will be treated the same as