I'm working on an assignment for my Python class and I'm super close to it being done but there's this one annoying issue that I can't seem to solve, but before I explain, here's my code:
import math as m
def distance(x1,y1,x2,y2):
xdel=(x2-x1)**2
ydel=(y2-y1)**2
print(xdel, "is xdel")
print(ydel, "is ydel")
dist = m.sqrt(xdel+ydel)
return dist
xl = []
yl = []
dists = []
while True:
ux = input("X for coordinate (blank for exit): ")
if ux == "":
break
ux = int(ux)
uy = int(input("Y for coordinate: "))
xl.append(ux)
yl.append(uy)
for i in range(len(xl)-2):
x2 = xl[i+1]
y2 = yl[i+1]
dist = distance(xl[i],yl[i],x2,y2)
dists.append(float(dist))
perimeter = sum(dists)
print(perimeter)
my list dists
is not being appended by the last line of code in the for loop, I don't know why. I feel like I've exhausted my freshman coding tricks to solve this, so I turn to you, oh noble wizards of StackOverflow.
EDIT: The point of the script is to take pairs of coordinates on a 2d graph from the user, gets the distance of all the lines, and gives the perimeter of the polygon that the lines make up. Sorry if that was not clear in the question. but no matter what the input is it would appear the list is still not being populated.