External Exam Download Resources Web Applications Games Recycle Bin

Exercise 5 - Distance To - Solution

BEGIN calculateDistance(X1,Y1,X2,Y2)
  RETURN SQRT((X2 - X1)^2 + (Y2 - Y1)^2)
END

BEGIN
  result = calculateDistance(1,1,2,2)
  PRINT result
END
import math
def calculateDistance(X1,Y1,X2,Y2):
  return math.sqrt(pow(X2 - X1, 2) + pow(Y2 - Y1, 2));

result = calculateDistance(1,1,2,2)
print(result) #1.4142135623730951