Diseña un programa que, dados cinco puntos en el plano, determine cuál de los cuatro últimos puntos es más cercano al primero. Un punto se representará con dos variables:
una para la abcisa y otra para la ordenada. La distancia entre dos puntos (x1, y1) y (x2, y2) es raiz((x1 − x2)**2 + (y1 − y2)**2).
#Solución
from math import sqrt
#Entrada
x1= int(input("ingrese x1: "))
y1= int(input("ingrese y1: "))
x2= int(input("ingrese x2: "))
y2= int(input("ingrese y2: "))
x3= int(input("ingrese x3: "))
y3= int(input("ingrese y3: "))
x4= int(input("ingrese x4: "))
y4= int(input("ingrese y4: "))
x5= int(input("ingrese x5: "))
y5= int(input("ingrese y5: "))
#Proceso
d1 = sqrt((x1 - x2)**2 + (y1 - y2)**2)
d2 = sqrt((x1 - x3)**2 + (y1 - y3)**2)
d3 = sqrt((x1 - x4)**2 + (y1 - y4)**2)
d4 = sqrt((x1 - x5)**2 + (y1 - y5)**2)
menor = d1
if d2 < menor:
menor = d2
r = "Tercer es menor"
if d3 < menor:
menor = d3
r = "Cuarto es menor"
if d4 < menor:
menor = d4
r = "Quinto es menor"
else:
r = "Segundo es menor"
#Salida
print(r)
Ayudanos a resolver más ejercicios!
https://www.paypal.com/paypalme/CwilVargas?locale.x=es_XC
Comentarios
Publicar un comentario