Write a function vote() that takes as a parameter a list of names of candidates
ID: 3763308 • Letter: W
Question
Write a function vote() that takes as a parameter a list of names of candidates up for election and repeatedly asks the user to enter a name of one of the candidates. When the user enters the empty string, the function prints for every name on the ballot the number of votes that the candidate received. The candidates and vote totals can be printed in any order as long as all of the information is presented. If the user types a name that cannot be found in the list of candidates, the vote is recorded for the 'Unknown' candidate. Capitalization shouldn't matter so that a candidate's name appearing in all uppercase, all lowercase, or in mixed case should record a vote for the associated person. When the user types a blank name, then the function should stop and report the vote totals. The vote totals should be reported using correct grammar, meaning using was/were and the singular or plural of vote appropriately. The following shows a sample run of the vote() function. Please note that your function must work on all valid examples, not just the ones provided above
Python 3.4.1 Shell Eile Edit Shell Debug Options Windos Help >>>vote (["Durbin", "Oberueiss", "Hansen") Enter a vote: Durbin Enter a vote: Hansen Enter a vote: OberTEISS Enter a vote: DURB IN Enter a vote: Settle Enter a vote: durbin Enter a vote: oberreisS Enter a vote: There vere 2 votes for Oberreiss. There vas 1 vote for Unknoun. There vere 3 votes for Durbin There as 1 vote for Hansen >>>vote('Quinn', Rauner', Gri) Enter a vote: QUINN Enter a vote: Rauner Enter a vote: RAUNER Enter a vote: rauner Enter a vote: grim Enter a vote: Quinn Enter a vote: quinn Enter a vote: rauner Enter a vote: settle Enter a vote: There vere 3 votes for Quinn. There vas 1 vote for Unknoun. There vere 4 votes for Rauner There as 1 vote for Gr imm Ln: 89 Col:4Explanation / Answer
from collections import Counter
vote = lambda *a:filter(a.__contains__,iter(lambda:raw_input("enter_name?"),""))
print votes.items()
Counter(vote("Durbin","Oberweiss","Hansen"))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.