大家好!我是编程新手,正在学习python 我有个问题: 如您所见,我正在创建一个程序,让您输入点的坐标,然后确定哪些点将是所有点(所有点的周长)的最外层。程序将生成周界中的点列表和周界中的另一个点列表的输出。我用所有点的质心作为所有点的距离的基础,但我找不到我应该如何识别每个点,将创建一个周长的所有点
import math
b=[]
a=[]
x1=[]
y1=[]
d1=[]
def cent(x):
return(sum(x)/len(x))
def dist (a,b,c,d):
return (math.sqrt(((c-a)**2)+((d-b)**2)))
c=2
print('Enter Point Coordinates')
while c>1:
x=int(input('x='))
y=int(input('y='))
b.append(x)
b.append(y)
x1.append(x)
y1.append(y)
a.append(b)
b=[]
r=input('Add more points?(Y/N): ')
if r.upper() == 'Y':
c+=1
else:
c=0
#print(cent(x1))
n=len(x1)
xc=cent(x1)
yc=cent(y1)
for i in range (n):
d=dist(xc,yc,x1[i],y1[i])
d1.append(d)
print (d1)
我被困在这里。。。我把我从质心的所有距离都写进了一个列表
#print(xc)
#print(yc)
#print(a)
#print(x1)
#print(y1)
目前没有回答
相关问题 更多 >
编程相关推荐