Question: I am able to pass the first 3 functions, but I am struggling on the add_candidate one. Here's the location of the csv and tester

I am able to pass the first 3 functions, but I am struggling on the add_candidate one.

Here's the location of the csv and tester file to test against add_candidate function:

https://drive.google.com/drive/folders/1bLSezhGdnzkbLZeGlKP6zcQK3j9endDx?usp=sharing

And the screenshot to the code:

I am able to pass the first 3 functions, but I amstruggling on the add_candidate one. Here's the location of the csv and

def add_candidate(db, state, name, party, popular_votes, electoral_votes):

#checks for matches in state, name, party

if (state) in db:

#starts loop over popular_votes and electoral_votes for the matches

for data in db[(state)]:

if data[1] == name:

db[(state)] = [(data[1] + name, party, popular_votes, electoral_votes)]

return

i = 0

for data in db [(state)]:

#checks if first entry greater than 'name'

if state[0] > data[1]:

break

i += 1

name_lst = db[(state)]

db[(state)] = name_lst[0:i] + [(name, party, popular_votes, electoral_votes)], name_lst[i:]

else:

db[(state)] = [(name, party, popular_votes, electoral_votes)]

db = read_votes('votes_copy.csv')

#works def read votes (filename): try: f - open (filename) f.readline () for line in f.readlines ) fieldsline.strip).split("," if fields [0] not in votes_db: 10 votes_db[fields [0]][(fields[1], fields [2], int(fields [3]), int(fields [4]))] else: 12 13 14 15 16 for state in votes_db [fields [0]]: if fields [1]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!