Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Question A1a: Extending Geometric Shapes (1 points) Complete the method l

ID: 3896324 • Letter: P

Question

Python Question A1a: Extending Geometric Shapes (1 points)

Complete the method length in the class Line that returns the length of the line.

Hint: You can use the Distance Formula to find the length of a line

Question A1a: Extending Geometric Shapes (1 points) Complete the method length in the class Line that returns the length of the line Hint: You can use the Distance Formula to find the length of a line class Shape: setorigin(self, x, y): self.x, self.y = x, y def def move(self, dx, dy): ""Move by dx and dy"" " self.x, self.y= self.x + dx, self.y + dy class Line (Shape) def _init (self, x, y, u, v) ""Line with start point (x, y) and end point (u, v)""" Shape.setOrigin(self, x, y) def move (self, dx, dy): Shape.move (self, dx, dy) self.u, self.v self.u + dx, self.v + dy def length(self) pass # Replace this Line with your answer def str (self): return "Line from (str (self.x) + ", " + str(self.y) ") to (" str(self.u)", "str(self.v) + ")" 1 Line(e, e, 3, 4) print (1) assert 1. length() 5.0

Explanation / Answer

Here is the code you wanted;

import math

class Shape:
def setOrigin(self,x,y):
self.x, self.y = x, y
  
def move(self,dx,dy):
seld.x,self.y = self.x + dx, self.y + dy
  
class Line(Shape):
def __init__(self,x,y,u,v):
Shape.setOrigin(self,x,y)
self.u,self.v = u, v
  
def move(self,dx,dy):
Shape.move(self,dx,dy)
self.u, self.v = self.u + dx , self.v + dy
  
def length(self):
return math.sqrt((self.u-self.x)**2 + (self.v-self.y)**2)
  
def __str__(self):
return "Line from (" + str(self.x) + "," + str(self.y) + ") to (" + str(self.u) + "," + str(self.v) + ") is"
  
  
l = Line(0,0,3,4)
print(l)
assert l.length() == 5.0