Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write a program tally() that takes a list of names of candiates up for

ID: 3644246 • Letter: I

Question

I need to write a program tally() that takes a list of names of candiates up for election and then asks the user to enter the name of one of the canidates repeatedly as a parameter. When the person using the program enters an empty string, the function will print for all the names that are on the ballot the number of votes that the canidate received. If the user types a name that doesn't exist in the list, then the vote is recorded for 'Other' canidate. CAPS also don't matter so however the user enters it should work. When a blank name is typed, then the function needs to stop and report all the totals of the vote count.

This is an example of how it should go.
* I know this code isn't complex, but I can't figure out how to exactly write it, But I know it's super simple, I gave it a try but struggled.* Sorry for re-posting, but the answer is actually quite short, not too long, trying to figure that one out specifically, having trouble if anyone knows that one??

>>> tally('John', 'Jim', 'Karda')
Enter a vote: John
Enter a vote: JIM
Enter a vote: karda
Enter a vote: KaRdA
Enter a vote: Haris
Enter a vote: Jim
Enter a vote: KARDA
Enter a vote:
Therewere 3 votes for Karda.
Therewere 2 votes for Jim.
There was 1 vote for John.
There was 1 vote for Other.

Explanation / Answer

def tally(names): votes=[] lnames=[] for n in names: votes.append(0) lnames.append(n.lower()) votes.append(0) done=False while not done: vote=raw_input("Enter a vote: ") vote=vote.lower() if vote=="": done=True continue if vote in lnames: place=lnames.index(vote) votes[place]=votes[place]+1 else: votes[len(votes)-1]=votes[len(votes)-1]+1 for i in range(len(names)): tense="was" vtense="vote" if votes[i]>1: tense="were" vtense="votes" print "There",tense,votes[i],vtense,"for",names[i]+"." tense ="was" vtense="vote" if votes[len(votes)-1]>1: tense="were" vtense="votes" print "There",tense,votes[len(votes)-1],vtense,"for","Other."