Hi, I am struggling with this assignment. I am asked to determine which county has the highest voter percentage (in decimal form only, i.e. population in the county/voters in the county) in each of the given county below.
The assignment calls for the output and print statement of the tuple of the 'name of the county' and the 'voter percentage'.
I've already created my class 'County' and the function for calculating the percentage of voters in each of the county, and then compare the initial voter percentage with the first county withe rest of the county in the list ('data'). Once the voter percentage is compared and determined with the other county voter percentage as to which has the highest voter percentage, it is updated as that voter percentage with that population.
What is wrong with my function? How can I print a tuple with only the name of the county with its highest voter percentage?
the format for each county in the given list is ('name of county', 'population', 'voters')
The assignment calls for the output and print statement of the tuple of the 'name of the county' and the 'voter percentage'.
I've already created my class 'County' and the function for calculating the percentage of voters in each of the county, and then compare the initial voter percentage with the first county withe rest of the county in the list ('data'). Once the voter percentage is compared and determined with the other county voter percentage as to which has the highest voter percentage, it is updated as that voter percentage with that population.
What is wrong with my function? How can I print a tuple with only the name of the county with its highest voter percentage?
class County: def __init__(self, name, population, voters): self.name = name self.population = population self.voters = voters def highest_turnout(data): people_county = data[0] total_people_county = data[0].population people_voted = data[0] total_number_voted = data[0].voters for County in data: voter_percentage = total_number_voted/total_people_population if voter_percentage > (data.voters/data.population): people_county = data total_people_county = data.population people_voted = data total_number_voted = data.voters return voter_percentage and total_people_voted # 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] result = highest_turnout(data) # do not change this line! print(result) # prints the output of the function # do not remove this line!
the format for each county in the given list is ('name of county', 'population', 'voters')