Quiz 09 – Distance

--Originally published at Programming

In this quiz we have to ask the user for the coordinates of two points in the cartesian plane, and then, calculate the distance between them. Let’s see the code:

Captura de pantalla 2017-03-16 a la(s) 10.51.12

First we importh math because we need the square root then. Our function that will do the magic is call distance, and here is where we write the variables. Finally in this part we write what we want it return, that is the formula of distance between two points. You can find more information about this here: Distance Between 2 Points.

Now, the second part is just to ask the user for the inputs like floats. There will be 2x and 2y, one by each point. Finally, we print the result. Original instructions didn’t ask for this step, but I included it because I think it helps to see how it works. You can avoid to follow the instructions correctly if you prefer.

And this is how it runs:

Captura de pantalla 2017-03-16 a la(s) 10.50.56 Hope it helps  ?

 


Quiz Week 09

--Originally published at Elu's Blog

For this assignment these were my instructions:

Write a function that receives four parameters: x1, y1, x2, y2 which are all floating point values.

The function is called distance and returns (float) the distance between x1,y1 and x2,y2 on the cartesian coordinate plane.

This is what I came up with:

Captura de pantalla 2017-03-09 a la(s) 10.57.40.png

Captura de pantalla 2017-03-09 a la(s) 10.57.56.png