Python Forum
Determining the Percentage of Voter Population
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determining the Percentage of Voter Population
#1
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?

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')
Reply


Messages In This Thread
Determining the Percentage of Voter Population - by Than999 - Dec-28-2019, 12:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Linked List - Ordering by largest population with country name. PaleHorse 2 2,982 Jun-16-2020, 09:04 PM
Last Post: jefsummers
  finding percentage in a list. samh625 3 5,632 Jun-15-2020, 06:49 PM
Last Post: samh625
  Numerically determining the highest a ball travels when shot straight up JakeWitten 3 3,453 Apr-22-2017, 04:37 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020