Hi, i am working on a Python project that i am having a really struggling & hard
ID: 3876712 • Letter: H
Question
Hi, i am working on a Python project that i am having a really struggling & hard time with. much help would be greatly appreciated The guidelines for it are:
Requirements: 1. Create a class named State that will store information about a US state and provide methods to get, and set the data, and compare the states.
a. Data attributes: State Name, Capital City, State Abbreviation, State Population, Region, US House Seats
b. Initializer (__init__)
c. Getter and setter methods for each field
d. __gt__ method so that two State objects can be compared based on state names
e. __str__ method so that a state object can be printed like a string
2. Create a program that will:
a. Read a file (csv) of states and create a list of state objects containing that data.
b. Offer the user the following options: 1) Print a state report 2) Sort by state name (using Quick Sort) 3) Sort by population (using Radix sort) 4) Find and print a given state (using binary search if the data is sorted by state name, sequential search if not) 5) Quit
c. Implement the given option, then prompt again. (deal with invalid choice) Your program should have functions for options 1-5.
d. The State report in option 1 should be in this form:
e.)e. The State report in option 5 should be in this form:
the input file to read from states.csv:
State,Capital,Abbreviation,Population,Region,US House Seats
Louisiana,Baton Rouge,LA,4625470,South,6
Wisconsin,Madison,WI,5742713,Midwest,8
New Mexico,Santa Fe,NM,2085287,Southwest,3
New York,Albany,NY,19651127,Middle Atlantic,27
Hawaii,Honolulu,HI,1404054,West,2
Vermont,Montpelier,VT,626630,New England,1
Indiana,Indianapolis,IN,6570902,Midwest,9
Arkansas,Little Rock,AR,2959373,South,4
Utah,Salt Lake City,UT,2900872,West,4
West Virginia,Charleston,WV,1854304,Middle Atlantic,3
Montana,Helena,MT,1015165,West,1
Maine,Augusta,ME,1328302,New England,2
Mississippi,Jackson,MS,2991207,South,4
Arizona,Phoenix,AZ,6626624,Southwest,9
North Dakota,Bismarck,ND,723393,Midwest,1
Texas,Austin,TX,26448193,Southwest,36
Ohio,Columbus,OH,11570808,Midwest,16
Alabama,Montgomery,AL,4833722,South,7
Maryland,Annapolis,MD,5928814,Middle Atlantic,8
Colorado,Denver,CO,5268367,West,7
Iowa,Des Moines,IA,3090416,Midwest,4
New Jersey,Trenton,NJ,8899339,Middle Atlantic,12
Massachusetts,Boston,MA,6692824,New England,9
North Carolina,Raleigh,NC,9848060,South,13
Washington,Olympia,WA,6971406,West,10
Pennsylvania,Harrisburg,PA,12773801,Middle Atlantic,18
Wyoming,Cheyenne,WY,582658,West,1
Missouri,Jefferson City,MO,6044171,Midwest,8
Nevada,Carson City,NV,2790136,West,4
Kansas,Topeka,KS,2893957,Midwest,4
Kentucky,Frankfort,KY,4395295,South,6
Delaware,Dover,DE,925749,Middle Atlantic,1
South Dakota,Pierre,SD,844877,Midwest,1
California,Sacramento,CA,38332521,West,53
Oregon,Salem,OR,3930065,West,5
Tennessee,Nashville,TN,6495978,South,9
Illinois,Springfield,IL,12882135,Midwest,18
New Hampshire,Concord,NH,1323459,New England,2
Virginia,Richmond,VA,8260405,Middle Atlantic,11
Idaho,Boise,ID,1612136,West,2
Nebraska,Lincoln,NE,1868516,Midwest,3
Minnesota,St Paul,MN,5420380,Midwest,8
Rhode Island,Providence,RI,1051511,New England,2
Alaska,Juno,AK,735132,West,1
Connecticut,Hartford,CT,3596080,New England,5
South Carolina,Columbia,SC,4774839,South,7
Florida,Tallahassee,FL,19552860,South,27
Michigan,Lansing,MI,9895622,Midwest,14
Oklahoma,Oklahoma City,OK,3850568,Southwest,5
Georgia,Atlanta,GA,9992167,South,14
d. The State report in option 1 should be in this form: State Name Capital City State Abbr State Population Region US House Seats 19,552, 860 12,773,801 6,692,824 Tallahassee EL 27 Florida Pennsylvania Harrisbur Massachusetts Boston Middle Atlantic New England MAExplanation / Answer
Program State.py
------------------------
class State:
def __init__(self,name,city, state_abbreviation, state_population, region, US_house_seats):
self.name = name
self.city = city
self.state_abbreviation = state_abbreviation
self.state_population = state_population
self.region = region
self.US_house_seats = US_house_seats
def get_name(self):
return self.name
def set_name(self, name):
self.name = name
def get_city(self):
return self.city
def set_city(self, city):
self.city = city
def get_state_abbreviation(self):
return self.state_abbreviation
def set_state_abbreviation(self, state_abbreviation):
self.state_abbreviation = state_abbreviation
def get_state_population(self):
return self.state_population
def set_state_population(self, state_population):
self.state_population = state_population
def get_region(self):
return self.region
def set_name(self, region):
self.region = region
def get_US_house_seats(self):
return self.US_house_seats
def set_US_house_seats(self, US_house_seats):
self.US_house_seats = US_house_seats
def __str__ (self):
print(usState.get_name() + " " + usState.get_city() + " " + usState.get_state_abbreviation() + " " +usState.get_state_population()
+" "+ usState.get_region() + " " + usState.get_US_house_seats())
file = open('Mytextt.txt')
content_list = file.readlines()
#print(content_list)
file.close()
personList = []
for fileEntry in content_list:
#print(fileEntry)
data = fileEntry.split(",")
personList.append(State(data[0],data[1],data[2],data[3],data[4],data[5]))
for usState in personList:
usState.__str__ ();
---------------- End-------------------
Input -- Mytextt.txt
-----------------------------
Louisiana,Baton Rouge,LA,4625470,South,6
Wisconsin,Madison,WI,5742713,Midwest,8
New Mexico,Santa Fe,NM,2085287,Southwest,3
New York,Albany,NY,19651127,Middle Atlantic,27
Output
--------------
Louisiana Baton Rouge LA 4625470 South 6
Wisconsin Madison WI 5742713 Midwest 8
New Mexico Santa Fe NM 2085287 Southwest 3
New York Albany NY 19651127 Middle Atlantic 27
Description
---------------------
As per chegg policy, i have provide first two answer as both the question itself has multiple questions. for rest of the question please post this question again with upated code so that chegg expert can provide solution on same.
1. Above given program has State class having setter and getter methods.
2. program read the csv file and create the State class object for each record using list
3. State class has str method to print the class properteis using setter and getter method.
Please let me know if you need any assitance on above given code. Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.