Question: Part 1 : Define the Rectangle Class ( 2 marks ) Define a class named Rectangle. The class should have two private attributes: width and

Part 1: Define the Rectangle Class (2 marks) Define a class named Rectangle. The class should have two private attributes: width and height (both default to 1.0).1 Include the following methods: init (self, width: float, height: float)- Constructor to Part 2: Part 3:initialize the width and height.get width(self)-> float - Returns the width.get height(self)-> float - Returns the height.set width(self, width: float)- Sets a new width (should vali- date that the width is positive).set height(self, height: float)- Sets a new height (should validate that the height is positive).calculate area(self)-> float - Returns the area of the rectan- gle (width \times height).calculate perimeter(self)-> float - Returns the perimeter of the rectangle (2\times (width + height)).Define the Circle Class (2 marks) Define a class named Circle. The class should have one private attribute: radius (default to 1.0). Include the following methods:init (self, radius: float)- Constructor to initialize the ra- dius.get radius(self)-> float - Returns the radius.set radius(self, radius: float)- Sets a new radius (shouldvalidate that the radius is positive).calculate area(self)-> float - Returns the area of the circle(\times radius2).calculate circumference(self)-> float - Returns the circum-ference of the circle (2\times \times radius).Instantiating and Testing the Classes (2 marks) Create an instance of the Rectangle class and set the width to 5.0 and the height to 3.0. Create an instance of the Circle class and set the radius to 4.0. Print the following details: The width, height, area, and perimeter of the rectangle. The radius, area, and circumference of the circle.2Part 4: Handling Invalid Input (1 mark) Modify the set width, set height, and set radius methods to raise a ValueError if a negative or zero value is passed.Expected OutputYour program should produce output similar to the following:Rectangle width: 5.0Rectangle height: 3.0Area: 15.0Perimeter: 16.0Circle radius: 4.0Area: 50.27Circumference: 25.13

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!