Question: Write a program that creates a class named Rectangle with the following details: Provide two ( 2 ) attributes: width and length.Provide an initialization method

Write a program that creates a class named Rectangle with the following details:
Provide two (2) attributes: width and length.Provide an initialization method (__init__) to accept initial values for width and length attributes and only accept these parameters if they are not negative numbers.Provide methods getWidth and getLength to return the value of width and length.Provide methods setWidth and setLength that each accepts one parameter. Assign the parameter value to the class variable (width or length) if the value is not negative.Provide a method called FindPerimeter that takes no parameters. This method computes and returns the perimeter as width+length.Provide the __str__ method to convert the object myRect to a string consisting of width, length, and perimeter.
Create an object named myRect from class Rectangle with a width of 40 and height of 20, then:
Change the width of myRect to 22 using the setWidth method.Use the getWidth and getLength methods of myRect to display the following messages:
Width of my rectangle is 22Length of my rectangle is 20
Print the following message on screen using the findPerimeter method of myRect:
Perimeter of my rectangle is x. Note: when you run your code, x will be the number returned by the findPerimeter method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!