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
#4
Some hints.
If i run the code,i can loop over data like this.
>>> for country in data:
...     print(country.name, country.population, country.voters)
... 
allegheny 1000490 645469
philadelphia 1134081 539069
montgomery 568952 399591
lancaster 345367 230278
delaware 414031 284538
chester 319919 230823
If eg make this function for percentage.
def percentage(voters, population):
    return 100 * voters / population
>>> for country in data:
...     print(country.name, percentage(country.voters, country.population))
... 
allegheny 64.51528750912053
philadelphia 47.53355359978696
montgomery 70.23281401594511
lancaster 66.67631823538439
delaware 68.72383951926305
chester 72.15045058280377
bucks 72.0064662984719
So this is stuff that you can have in highest_turnout function.
Now can try find highest voter percentage in the loop,or collect data and use max() if that allowed.
Place this function highest_turnout outside of class,not in the class as you have in first code.
Can place a function in class,as just a function with using @staticmethod.
Reply


Messages In This Thread
RE: Determining the Percentage of Voter Population - by snippsat - Dec-28-2019, 08:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Linked List - Ordering by largest population with country name. PaleHorse 2 3,039 Jun-16-2020, 09:04 PM
Last Post: jefsummers
  finding percentage in a list. samh625 3 5,719 Jun-15-2020, 06:49 PM
Last Post: samh625
  Numerically determining the highest a ball travels when shot straight up JakeWitten 3 3,491 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