407037: GYM102697 008 N-Dimensional Distance
Description
Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and display the distance between them as you normally would with the distance formula.
The n-dimensional distance formula can be expressed as
$$$d(p,q) = \sqrt{(q_{1}-p_{1})^2 + (q_{2}-p_{2})^2 + ... + (q_{n}-p_{n})^2}$$$
or in other terms:
$$$\sqrt{\sum_{i=1}^{n} (q_{i}-p_{i})^2} = d$$$
Remember that math.sqrt will calculate the square root of a number (you also have to add the line import math at the top of the program).
InputThe first line contains the dimension D between 2 and 500. Then, D test cases will follow.
Each test case N will consist of two lines: the value of the first point, and the value of the second point, in the Nth dimension.
Each of these values is an integer between -5000 and 5000, inclusive.
OutputA decimal number N representing the distance between the two points. Do not round your answer.
ExamplesInput2 1 1 1 2Output
1.0Input
3 7 4 3 17 6 2Output
14.866068747318506Input
4 -2367 -2873 -4279 -2321 -1302 -1341 -2893 651Output
4080.5951771769764