logo CodeStepByStep logo

Rectangle_contains

Language/Type: Python classes
Related Links:

(Use your Rectangle class solution from the previous problem as a starting point to solve this problem.) Suppose a class named Rectangle has already been created that has the following members:

member name type description
Rectangle(x, y, w, h) constructor Initializes a new rectangle whose top-left corner is specified by the given (x, y) coordinates and with the given width and height, w by h. Raises a ValueError on a negative width or height.
ba._x,
ba._y,
ba._width,
ba._height
data attributes private attributes storing rectangle coordinates
ba.x,
ba.y,
ba.width,
ba.height
property the rectangle location and dimensions (read-only)
str(r) method returns a string representation of the rectangle, such as "Rectangle[x=1,y=2,width=3,height=4]".

Add an accessor method named contains to your class. Your method should return True if the given coordinates lie inside the bounds of the rectangle.

Type your Python solution code here:

This is a class exercise. Submit a complete Python class as described.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.