Dec-28-2019, 08:15 PM
Some hints.
If i run the code,i can loop over data like this.
Now can try find highest voter percentage in the loop,or collect data and use
Place this function
Can place a function in class,as just a function with using
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 230823If 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.0064662984719So 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
.