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()Tier 1 · geometry
Distance 2D
Distance between two points in 2D.
Files (1)
How to use it
Launch DIST2D from prgm, choose 1:DIST, then enter the four coordinates in this order:
x1:x of the first point.y1:y of the first point.x2:x of the second point.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).
- Run
DIST2D, choose1:DIST. x1:→ 1,y1:→ 2,x2:→ 4,y2:→ 6.- 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)
| ID | Inputs | Expected contains |
|---|---|---|
| origin-to-3-4 | 1, 0, 0, 3, 4, 0 | d=5.0 |
| 1-2-to-4-6 | 1, 1, 2, 4, 6, 0 | d=5.0 |