Question: 1 . Create Point class Create a Point class that has both an x and a y attribute. Think of it as the representation of

1. Create Point class
Create a Point class that has both an x and a y attribute. Think of it as the representation of a point on an (x,y) coordinate graph.
Create a class with the following properties:
The class name is Point
It has the attributes x and y which are both floats
Now, define a constructor (aka an __init__ method) that takes as input x_init: float and y_init: float and assigns those as the initial values for the attributes x and y.
2. Mutating Method: Point#scale_by
Write a method that belongs to the Point class and mutates a Point.
Itll should the following properties:
Method name: scale_by
Parameters: self and factor: int (In general, the first parameter of a method should always be self)
Return Type: None
Behavior: It should update the x and y attributes so that x = x * factor and y = y * factor
3. Mutating Method: Point#scale
Write a method that belongs to the Point class and instead of mutating a Point, it creates a new Point.
Itll should the following properties:
Method name: scale
Parameters: self and factor: int (In general, the first parameter of a method should always be self)
Return Type: Point *
Behavior: It should return a new Point with x and y attributes equal to self.x * factor and self.y * factor.

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