-1

I tried this

import math
from math import sqrt
def euclideanDistance(xtr, ytr, Ltr):
 distance = 0
 for x in range(Ltr):
    distance += pow((xtr[x] - ytr[x]), 2)
return sqrt(distance)

But it returned me the following error:

File "<stdin>", line 5
    return sqrt(distance)
         ^
SyntaxError: invalid syntax

What is the cause of this syntax error?

Stop harming Monica
  • 12,141
  • 1
  • 36
  • 56
Rifat
  • 3
  • 1
  • 3
  • @anil: Please don't change the indentation of Python questions. Frequently (such as in this case), the indentation is the cause of the error. – user2357112 Sep 30 '16 at 07:22
  • @user2357112 , I realized that. Thanks for pointing out. In my answer, that's why I mentioned specifically that I considered code in the picture attached. – AV94 Sep 30 '16 at 07:24

1 Answers1

1

From the picture you have attached, The problem is with the return statement indentation. The following is the correct indentation.

from math import sqrt;
def euclideanDistance(xtr, ytr, Ltr):
    distance = 0
    for x in range(Ltr):
        distance += pow((xtr[x] - ytr[x]), 2)
    return sqrt(distance)

Above code ran without any errors.

AV94
  • 1,824
  • 3
  • 23
  • 36