Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active July 16, 2021 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minte9/ed6c6cac3defb70f06cf13ed6fcada76 to your computer and use it in GitHub Desktop.
Save minte9/ed6c6cac3defb70f06cf13ed6fcada76 to your computer and use it in GitHub Desktop.
# Write a function named distance_between_points()
# that takes 2 Point as argument
# and return the distance between them
import math
class Point: """ a 2D point """
a = Point()
a.x = 0.0
a.y = 0.0
b = Point()
b.x = 3.0
b.y = 4.0
# SOLUTION
def distance_between_points(p1, p2):
dx = (p2.x - p1.x)**2
dy = (p2.y - p1.y)**2
return math.sqrt(dx + dy)
print(distance_between_points(a, b)) # 5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment