Generation

generate functionSun, 25 Dec 2022

Point objects have x and y attributes (X and Y in C#) attributes. Write a function calculating distance between Point a and Point b. Tests round answers to 6 decimal places.

import math class Point(object): def __init__(self, x=0, y=0): self.x = x self.y = y # TODO Write a function calculating distance between Point a and Point b. def distance(a, b): c = math.sqrt((a.x - b.x)**2 + (a.y - b.y)**2) return c a = Point(1,1) b = Point(1,2) print(distance(a,b))

Questions about programming?Chat with your personal AI assistant