Question
Python 3 1. Implement the scale method. class Point: def __init__(self, initX, initY): Create a new point at the given coordinates self.__x =
Python 3
1. Implement the scale method.
class Point:
def __init__(self, initX, initY):
""" Create a new point at the given coordinates """
self.__x = initX
self.__y = initY
def getX(self):
""" Get its x coordinate """
return self.__x
def getY(self):
""" Get its y coordinate """
return self.__y
def __str__(self):
""" Return a string representation of the point """
return "({}, {})".format(self.__x, self.__y)
def scale(self, val):
""" Return a new point that is self multiplied by val """
if __name__ == "__main__":
import test
2. We can represent a rectangle by knowing three things: the location of its lower left corner (its starting point), its width, and its height. Write a class definition and constructor method for a Rectangle class (after the definition for the Point class) using this idea. To instantiate a Rectangle object at location (4,5) with width 6 and height 5, we would do the following:
r = Rectangle(Point(4, 5), 6, 5)
class Point:
def __init__(self, initX, initY):
""" Create a new point at the given coordinates """
self.__x = initX
self.__y = initY
def __str__(self):
""" Return a string representation of the point """
return "({}, {})".format(self.__x, self.__y)
# your code goes here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started