Saltar al contenido

Ejemplo de código de lista de Python de distancia de Manhattan

Ejemplo 1: pitón de distancia euclidiana

# I hope to be of help and to have understood the request
from math import sqrt # import square root from the math module
# the x and y coordinates are the points on the Cartesian plane
pointA = (x, y) # first point
pointB = (x, y) # second point
distance = calc_distance(pointA, pointB) # here your beautiful result
def calc_distance(p1, p2): # simple function, I hope you are more comfortable
  return sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) # Pythagorean theorem

Ejemplo 2: como hacer una función de distancia en Python

import math
p1 = [4, 0]
p2 = [6, 6]
distance = math.sqrt( ((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2) )

print(distance)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *