Question: IESTION 1 Define a new style class Rectangle, whose instances have attributes width and height, both expected to be numbers. When Rectangle() is calle eturns

 IESTION 1 Define a new style class Rectangle, whose instances have
attributes width and height, both expected to be numbers. When Rectangle() is

IESTION 1 Define a new style class Rectangle, whose instances have attributes width and height, both expected to be numbers. When Rectangle() is calle eturns a string of the form (width) x (height) rectangle", where (width) is the value of self.width and height) is the value of welt. needed. An instance of Rectangle has a method area () that retums the product of its width and height attributes Next, define a class ScalableRectangle that inherits from Rectangle, adding only the method scale(), which, passed a number, updates the w The following is test code in the file where both these classes are defined in our solution name r1 = Rectangle(4.0, 2.0) print("A (0) with area (1: 10)".Format (ri, ri.area())) if "main": sr = ScalableRectangle(5.0, 3.0) print("A 10) with area (1: 10)".Format(st, sr.area())) Sr. scale (2.0) print("A toj with area (1: 10)". format (st, sr.area())) The following is the output produced A 4.0 x 2.0 rectangle with area 8.0 A5.0 X 3.0 rectangle with area 15.0 A 10.0 X 6.0 rectangle with area 60.0 For the toolbar, press ALT-F10 (PC) O ALT-FN-F10 (Mac) il Q A G K s called, it is passed values for both these attributes. When an instance of Rectangle appears where a string is expected, it self. height: both values should be formatted to have one digit after the decimal point and to occupy as much space as tes the width and height of an instance by multiplying both by that number

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 Databases Questions!