Question: PYTHON CODE WITH CLASS AND OBJECT! Hi. I need to write a code to turn out the name of the County which has the highest

PYTHON CODE WITH CLASS AND OBJECT!

Hi. I need to write a code to turn out the name of the County which has the highest voter turnout and percentage of population voted. Here is what I have done:

class County: def __init__(self, init_name, init_population, init_voters) : self.name = init_name self.population = init_population self.voters = init_voters # your program will be evaluated using these objects # it is okay to change/remove these lines but your program # will be evaluated using these as inputs allegheny = County("allegheny", 1000490, 645469) philadelphia = County("philadelphia", 1134081, 539069) montgomery = County("montgomery", 568952, 399591) lancaster = County("lancaster", 345367, 230278) delaware = County("delaware", 414031, 284538) chester = County("chester", 319919, 230823) bucks = County("bucks", 444149, 319816) data = [allegheny, philadelphia, montgomery, lancaster, delaware, chester, bucks]

# find the highest voter turnout def highest_turnout(self): highest = self[0] highest_voters = self[0].voters for county in data: if county.voters > highest_voters: highest = county result = highest_turnout(self) print(result)

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!