Expert answer:All scripts should consist of a main function that includes a call to a function that includes the code. The optional scripts are simply for your learning and enjoyment, not for extra credit.First Script (Required) – Reading a data file:In this problem you will use a file which is named states.txt The states.txt file is located in Canvas (be sure you get the file with .txt extnsion). You will need to copy this file to your local working directory.Log in to Canvas.Select CIS 41A.Select files.Select states.txtMove your cursor to the right of the green checkmark icon.Click the down arrow next to the gear.Click DownloadClick Save File and OKThe file should be on your desktop or download directory. Move the file to the directory constining your Python program.The file has 50 lines of data, one for each state in the Unites States. Each line of data contains three pieces of data separated by a space: the two letter abbreviation of the state’s name, the region that the state is in, and the 2016 population of the state.You need to find the state with the highest population in the Midwest region.Sample Execution Results:Highest population state in the Midwest is: IL 1280200
**Here is what I have so far and need help:**
import redef states(): myFile = open(“States.txt”, “r”) myFile.readline() for lines in myFile: if re.search(r”Midwest”, lines): print(“Highest population state in the Midwest is:”, lines) myFile.close()In-class assignmentDictionariesThis assignment consists of three parts.Part 1 of 3 – Dictionary Basics:Create a dictionary of fruit and desserts made from the fruit. The fruit should be the key and the dessert should be the value. Use these key value pairs: apple:sauce, peach:cobbler, carrot:cake, strawberry: sorbet, banana:cream pie.Add the mango fruit to the dictionary. Its dessert is sticky rice.Change the strawberry dessert to shortcake.Carrot is not a fruit, so remove carrot from the dictionary.Print the apple dessert.See if a banana dessert exists.See if a pear dessert does not exist.Iterate through the dictionary using the items method and print the results (key and value).Iterate through the dictionary using the keys and print the sorted results (key and value).Sample Execution Results:e)
apple dessert is: sauce
f)
A banana dessert exists.
g)
A pear dessert does not exist.
h)
strawberry shortcake
apple sauce
banana cream pie
peach cobbler
mango sticky rice
i)
apple sauce
banana cream pie
mango sticky rice
peach cobbler
strawberry shortcake
Part 2 of 3 – Zipping Lists to make a Dictionary:Create a list of states that contains the following states (in this order): Alabama, Alaska, Arizona, Arkansas, California Create a list of capitals that contains the following capitals (in this order): Montgomery, Juneau, Phoenix, Little Rock, SacramentoYou now have a pair of ordered lists that correspond to each other – Montgomery is the capitol of Alabama, Juneau is the capital of Alaska, and so on.Create a dictionary that combines these lists into a dictionary with state as the key and capitol as the value. Use the built-in-functions dict and zip – see: dict function and zip function . You should be able to do this with one line of code.Iterate through the dictionary and print the sorted results (key and value).Sample Execution Results:Alabama Montgomery
Alaska Juneau
Arizona Phoenix
Arkansas Little Rock
California Sacramento
Part 3 of 3 – Combining Dictionaries:Create a new dictionary of state capitols and populate it with these key value pairs: California: Sac., Colorado: Denver, Connecticut: Hartford. Be sure that the California capitol is Sac. and not Sacramento.Using the dictionary update method, (see: update method ) update the dictionary from Part 2 above with your newly created dictionary.Iterate through the updated dictionary and print the sorted results (key and value). Note the updated value of California’s capitol.Sample Execution Results:Alabama Montgomery
Alaska Juneau
Arizona Phoenix
Arkansas Little Rock
California Sac.
Colorado Denver
Connecticut Hartford
Unit IIn-class assignmentObjects and ClassesThis assignment consists of three parts.Part 1 of 3 – A Basic Class – State Data:Create a StateData class with the following methods: __init__, __str__, displayState.Note: __ is two underline characters.The __init__ method should have the parameters self, name, abbreviation, region, and population and should store the name, abbreviation, region, and population as attributes.The __str__ method has the parameter self and should return the state’s name.The displayState method has the parameter self and should print formatted state data as shown below.Test the class by creating an instance of the class (instantiating) called s1 with the following data: “California”, “CA”, “West”, 39250000. Print your state object (this will call the __str__ method). Then call displayState. This test code should be after your class code – don’t worry about calling from main.Sample Execution Results:California
California (CA) is in the West region and has population of 39250000
Part 2 of 3 – Different ways of working with Attributes:Here we explore different ways to work with Python attributes. Note that, while one of the approaches we are using is set/get, this approach is generally deprecated in favor of the simpler dot notation. Perhaps the only reason you might want to use set/get methods is when you need to run some extra code within the class whenever you are setting or getting an attribute. See the introduction to propertiesCreate a StateData2 class with the following methods: __init__, setRegion, getRegion.The __init__ method should have the parameters self, name and should store the name as an attribute.The setRegion should have the parameters self, region and should store the region as an attribute.The getRegion should have the the parameter self and should return the the value of the region data variable.Test the class by creating an instance of the class called s2 with the following data: “California”. Then call setRegion with the argument “West”. Then set the population attribute with the following line of code: s2.pop = 39250000Then print four lines: s2.name, s2.getRegion(), s2.region, s2.popAgain, this test code should be after your class code.Sample Execution Results:California
West
West
39250000
Part 3 of 3 – Data Hiding:Data hiding within Python is achieved with the use of special naming conventions: beginning an attribute name with either a single underscore (protected) or a double underscore (private). See:object oriented programming (scroll down to the Public- Protected- and Private Attributes section).Create a StateData2 class with the following method: __init__.The __init__ method should have the parameter self. It should store the value “Public” in an attribute called public, the value ” Protected” in an attribute called _protected (use a single underscore), and the value ” Private” in an attribute called __private (use a double underscore).Test the class by creating an instance of the class called test.Try to print three lines: test.public, test._protected, test.__privateSample Execution Results:PublicProtectedTraceback errorUnit JIn-class assignmentChapter 9 continedChapter 10: InheritancePart 1 of 1 – Basic Inheritance – Circle & Cylinder:You will be creating a Circle base (parent) class and a Cylinder class that inherits from it (child). Both classes and the code to test the classes will be contained within a single script.The Circle class has the following methods: __init__, getArea.Circle’s __init__ method should have the parameters self and radius, and should store the radius as an attribute.The getArea method has the parameter self and should return the circle’s area (use the pi constant from the math module when calculating the area).The Cylinder class inherits from the Circle class and has the following methods: __init__, getVolume.Cylinder’s __init__ method should have the parameters self, radius and height. From within Cylinder’s __init__, call Circle’s __init__ to store the radius. The height should be stored as an attribute of the Cylinder.The getVolume method has the parameter self and should return the cylinder’s volume. See: volume of a cylinderTest by creating an instance of the Circle class with a radius of 4. Print the area of the circle, rounded to 2 places.Then, create an instance of the Cylinder class with a radius of 2 and a height of 5. Print the volume of the cylinder, rounded to 2 places.Sample Execution Results:Circle area is: 50.27
Cylinder volume is: 62.83
states.txt
Unformatted Attachment Preview
AL South 4863000
AK West 742000
AZ West 6931000
AR South 2988000
CA West 39250000
CO West 5541000
CT Northeast 3576000
DE South 952000
FL South 20612000
GA South 10310000
HI West 1429000
ID West 1683000
IL Midwest 12802000
IN Midwest 6633000
IA Midwest 3135000
KS Midwest 2907000
KY South 4437000
LA South 4682000
ME Northeast 1331000
MD South 6016000
MA Northeast 6812000
MI Midwest 9928000
MN Midwest 5520000
MS South 2989000
MO Midwest 6093000
MT West 1043000
NE Midwest 1907000
NV West 2940000
NH Northeast 1335000
NJ Northeast 8944000
NM West 2081000
NY Northeast 19745000
NC South 10147000
ND Midwest 758000
OH Midwest 11614000
OK South 3924000
OR West 4093000
PA Northeast 12784000
RI Northeast 1056000
SC South 4961000
SD Midwest 865000
TN South 6651000
TX South 27863000
UT West 3051000
VT Northeast 625000
VA South 8412000
WA West 7288000
WV South 1831000
WI Midwest 5779000
WY West 586000
…
Purchase answer to see full
attachment
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more