class Point definitseIf initx inity sel fx initx selfx is
class Point: def__init__(seIf, init_x, init_y): sel f.x = init_x # self.x is an instance variable self.y = init_y # self.y is an instance variable def__str__(self): return \'({}, {})\'. format (self .x, self.y) def move(self, dx, dy): self.x += dx self.y += dy # Write statements in Python for each of the following. # For each, write a single statement. # # a) Create a Point with co-ordinates x = 2 and y = 3. # Store this object in a variable called p. p = None # modify this print(p) # b) Move the point to co-ordinates (4, 4). p = None # change this to a method call that moves co-ordinates print(p) # c) display p, implicitly using the __str__ method. # print(p) ### you get this problem for free!!
Solution
a)Create a Point with coordinates x=2 and y=3.Store this object in a variable called p
p = Point(2,3)
print(p)
b)Move the point to coordinates (4,4).
p.move(2,1)
print(p)
c)
print(p)
