Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODE WITH CLASS AND OBJECT! Hi. I need to write a code to turn out the name of the County which has the highest

PYTHON CODE WITH CLASS AND OBJECT!

Hi. I need to write a code to turn out the name of the County which has the highest voter turnout and percentage of population voted. Here is what I have done:

class County: def __init__(self, init_name, init_population, init_voters) : self.name = init_name self.population = init_population self.voters = init_voters # 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]

# find the highest voter turnout def highest_turnout(self): highest = self[0] highest_voters = self[0].voters for county in data: if county.voters > highest_voters: highest = county result = highest_turnout(self) print(result)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

Compare and contrast cultural preferences for privacy

Answered: 1 week ago