Home / Expert Answers / Computer Science / how-to-do-question-4d-in-python-nbsp-question-4a-create-an-exception-class-invaliddeptherror-d-pa934

(Solved): How to do QUESTION 4D in python?  Question 4a. Create an exception class InvalidDepthError. D ...



How to do QUESTION 4D in python? 

Question 4a.
Create an exception class InvalidDepthError. Define a _str____ dunder method for this class
to return a string

Question 4a. Create an exception class InvalidDepthError. Define a _str____ dunder method for this class to return a string "Invalid Depth". Question 4b. Define a class that meets the following specifications. Class name WaterBody Class constructor 1. int/float parameter Assign this number to the instance attribute volume Class attribute The class has class attributes RHO = 997 and G = 9.81. Question 4c. Define a class method that meets the following specifications. get_hydrostatic_pressure Method name Method parameter 1. Float, depth Return value 1. float Detailed information Using the parameter float, the depth. calculate and return the hydrostatic pressure. Hydrostatic pressure a given depth = RHO*G*depth If the depth is less than 0, the static method should raise an InvalidDepthError. This should be defined in question 3a. Question 4d. Define an instance method that meets the following specifications. Method name get_water_mass Method parameter Return value 1. Float Detailed information This method should return the mass of the waterbody given that mass= RHO* volume, where volume is the object's instance attribute.


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer (4a): In the python program, we will create a class named "InvalidDepthError" that will return a string "Invalid Depth" with the help of a "__str__" dunder method. In the main class we will take the entry of the depth from the user and then wi
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe