Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in python please Lab 1 2 A: Having a seat When learning about objects, you may hear the example a chair is an object .
in python please
LabA: Having a seat
When learning about objects, you may hear the example a chair is an object Well, for this lab, we are going to implement this example. Create a class called Chair which can create Chair objects.
Chair class:
class Chair:
# attributes of a chair
numOfLegs # how many legs are on the chair
rolling False # does it roll or not
material plastic # what is the chair made of
Using these attributes you can describe most chairs. For example, you might have a wooden chair with legs that does not roll, or you may have a rolling chair made of leather with legs. The code above will allow you to create Chair objects, each with their own copies of the attributes available to a Chair, as below:
c Chair # creates a Chair
printcnumOfLegs # prints the numOfLegs attribute of c
crolling True # cs rolling attribute is now True
Another way for you to create a Chair class is by initializing the fields inside a constructor. Whenever an object is created, the constructor is the first piece of code which runs, and it is used to initialize the fields of the object of a valid state. In Python, the constructor is called init and looks like any other method, with the exception that it always has at least one parameter, called self Its syntax can be found below:
class Chair:
def initself numOfLegs rolling False, material plastic:
self.numOfLegs numOfLegs
self.rolling rolling
self.material material
For the purposes of this lab, either of the two ways above to create a Chair class will work. However, they can lead to different behavior, which we will see in the next lab.
This class isnt going to have any methods, so unless you are adding the constructor, your class should only have the three attributes above.
Outside of the class body, create a Chair object. Then, take user input for the attributes for the Chair object and assign them to the object. Once you have done that, print out the information about your chair, as per the sample output below. Finally, inform the user you will be changing the information, change the attributes of the Chair object to have legs, to not be rolling, and to be made of wood, and print the Chairs information one last time.
Tip: When dealing with rollingnot rolling you may want to use an IF statement with different print statements.
See Sample Output in the next page. The user input is indicated in bold.
Sample output:
You are about to create a chair.
How many legs does your chair have:
Is your chair rolling truefalse: true
What is your chair made of: plastic
Your chair has legs, is rolling, and is made of plastic.
This program is going to change that.
Your chair has legs, is not rolling, and is made of wood.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started