I'm still new to python and have been trying to get the hang of it. I've been trying to learn simple return methods but I can't seem to get the hang of it. I have been trying to find the distance between two points and this is what I have so far. If anyone could help me figure this out it would be very helpful! Thank you!
import math
def calculateDistance(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
calculateDistance(2,4,6,8)
print calculateDistance
Why don't you use math.hypot() to calculate the distance?
>>> import math
>>> p1 = (3, 5) # point 1 coordinate
>>> p2 = (5, 7) # point 2 coordinate
>>> math.hypot(p2[0] - p1[0], p2[1] - p1[1]) # Linear distance
2.8284271247461903
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With