Last active
December 17, 2015 11:49
-
-
Save Nicksil/5605332 to your computer and use it in GitHub Desktop.
Python Pythagorean Theorem - Distance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
# Pythagorean theorem | |
# a² + b² = c² | |
def distance(p, q): | |
return math.sqrt((p[0] - q[0])**2 + (p[1] - q[1])**2) | |
# >>> distance([200, 250], (300, 350)) | |
# 141.4213562373095 | |
# >>> distance([200, 250], (200, 250)) | |
# 0.0 | |
# >>> distance([200, 250], (200, 220)) | |
# 30.0 | |
# >>> distance([200, 250], (200, 260)) | |
# 10.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment