At the top of your script, put the following multi-line comment with your information:
'''
Your name as registered, with optional nickname in parentheses
CIS 41A Fall 2021
Unit H, Exercise H
'''
Create a StateData class with the following methods:
__init__, __str__, displayState.
Note: __ is two underline characters (dunder).
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
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.
Create 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 = 39250000
Then print four lines: s2.name, s2.getRegion(), s2.region, s2.pop
Again, this test code should be after your class code.
Sample Execution Results:
California West West 39250000
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).
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.__private
Sample Execution Results:
Public
Protected
Traceback error
Add the following at the end of the script to show your results:
'''
Execution results:
paste execution results here
'''
Submit your finished py script in Canvas, Exercise H.