Your problem is that exponentiality in Python is done using a ** b , not a ^ b ( ^ is a bitwise XOR), which makes final a negative value, which causes a domain error.
Your fixed code:
def distance(x1, y1, x2, y2): return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5
source share