← Library
Tier 1 · geometry

Distance 2D

Distance between two points in 2D.

Files (1)
DIST2D.py306 bytes
def p(s):print(s)
def o1():
 p("=DIST=")
 a=float(input("x1:"))
 b=float(input("y1:"))
 c=float(input("x2:"))
 e=float(input("y2:"))
 d=((c-a)**2+(e-b)**2)**0.5
 p("d="+str(d))
def menu():
 while True:
  p("=DIST 2D=")
  p("1:DIST")
  p("0:EXIT")
  c=input("?>")
  if c=="1":o1()
  elif c=="0":break
menu()
How to use it

Launch DIST2D from prgm, choose 1:DIST, then enter the four coordinates in this order:

  1. x1: x of the first point.
  2. y1: y of the first point.
  3. x2: x of the second point.
  4. y2: y of the second point.

Output is d= with the Euclidean distance. Press 0 at the main menu to exit.

Example problem

Find the distance between (1, 2) and (4, 6).

  1. Run DIST2D, choose 1:DIST.
  2. x1:1, y1:2, x2:4, y2:6.
  3. Output: d=5.0.

Verify with the distance formula: √((4−1)² + (6−2)²) = √(9+16) = √25 = 5. ✓

TI-84 Plus CE — try before committingoff
TI-84 Plus CE



  (calculator off)

  Press ON to start.
Test cases (2)
IDInputsExpected contains
origin-to-3-41, 0, 0, 3, 4, 0d=5.0
1-2-to-4-61, 1, 2, 4, 6, 0d=5.0