Question: Python Question: Complete the implementation of the highest_turnout function so that it does the following: First, find the County that has the highest turnout, i.e.
Python Question:
Complete the implementation of the highest_turnout function so that it does the following:
-
First, find the County that has the highest turnout, i.e. the highest percentage of the
population who voted, using the objects population and voters attributes
-
Then, return a tuple containing the name of the County with the highest turnout and the
percentage of the population who voted, in that order; the percentage should be represented as a number between 0 and 1
This is what I have so far:
class County: def __init__(self, init_name, init_population, init_voters): self.name = init_name self.population = init_population self.voters = init_voters
@property def highest_turnout(self): return 100 * (self.voters / self.population)
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) print(result)
####********
I get:
Error on line 25: result = highest_turnout(data)
NameError: name 'highest_turnout' is not defined
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
