I am trying to write code to solve this python exercise: I must use the 'math' library, sqrt and possibly pow functions.
"The distance between two points x and y is the square root of the sum of squared differences along each dimension of x and y.
"Create a function that takes two vectors and outputs the distance between them.
x = (0,0) y = (1,1)"
So far I've tried this - which certainly hasn't worked.
x = (0,0)
y = (1,1)
(c1, c2) = x
(c3, c4) = y
math.sqrt(sum((c1,**2)(c2,**2)(c3,**2)(c4,**2)))
File "<ipython-input-14-ac0f3dc1fdeb>", line 1 math.sqrt(sum((c1,**2)(c2,**2)(c3,**2)(c4,**2))) ^ SyntaxError: invalid syntax
if c1 < c3:
difference1 = c3-c1
print(difference1)
1
... not even sure if that's the kind of calculation I should be working with.
def distance(x, y):
ummm... I expect the function starts by unpacking the tuples! But not sure how to write the rest of it, or cleanly.
I'm a beginner programmer & not a mathematician so I may be wrong in more than one sense... This exercise is from this HarvardX course: 'Using Python for Research'.
It's OK to search for solutions via StackOverflow for learning on this course... not cheating to ask for pointers.
Many thanks for any ideas! I will keep searching around.