Lesson goal: The distance formula with variables

Previous: Calculate a tip (with keyboard input) | Home | Next: Changing a variable in one line

In a past lesson, the distance formula as covered, which is $d=\sqrt{(x-x_0)^2+(y-y_0)^2}$. This formula will tell you the "straight line" distance between any two points on a cartesian coordinate system. As this formula is stated, one point will be $(x,y)$ and the other will be $(x_0,y_0)$.

The implementation in the past lesson was a bit cumbersome. Using variables makes it much more convenient. In this lesson, we'll see if you can program and use the distance formula using variables.

Now you try. Use the print statement to find the distance between two xy points using the variables defined.

Type your code here:

See your results here:

You have to admit, the variables make this distance formula program very clear to read and easy to use! But this is the power of variables! Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.