Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # implement County class here
- class County:
- def __init__(self, init_name, init_population, init_voters):
- self.name = init_name
- self.population = init_population
- self.voters = init_voters
- self.turnout = self.voters / self.population
- def highest_turnout(data):
- # implement the function here
- maxCounty = '' # You want the variable to match the data type you're comparing, so string
- maxTO= 0 # Holds the greatest maxTO
- for item in data: # Iterates through items in data using item as iterator
- if item.turnout > maxTO:
- maxCounty = item.name # Sets maxCounty to name of county if condition is met
- maxTO = item.turnout # Sets maxTo to turnout if higher than current maxTO
- print(maxCounty)
- print(maxTO)
- tuple = (maxCounty, maxTO)
- print('this is the tuple', tuple)
- return tuple # modify this as needed
- # 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", 10000, 6500)
- philadelphia = County("philadelphia", 100, 25)
- montgomery = County("montgomery", 500, 475)
- lancaster = County("lancaster", 7000, 798)
- data = [allegheny, philadelphia, montgomery, lancaster]
- result = highest_turnout(data) # do not change this line!
- print(result) # prints the output of the function
- # do not remove this line!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement