【发布时间】:2020-12-29 18:45:25
【问题描述】:
我是初学者。我有一个问题,我们如何访问列表中元组的值。示例
def point_function():
my_list=[]
num=int(input("Dear User, How many points you want to enter: "))
for i in range(1,num+1):
print(f"Please input the coordinates of the point {i}")
x=float(input("Please enter x-coordinate of the point: "))
y=float(input("Please enter y-coordinate of the point: "))
my_tuple=(x,y)
my_list.append(my_tuple)
print(my_list)
point_function()
这个函数将创建一个存储点坐标的元组列表,现在如果我想访问它们并找到所有点之间的距离。覆盖点和其后点之间的距离。我该怎么做?
我试图搜索它,但我没有得到任何合适的答案。 提前感谢您的回答。
【问题讨论】:
-
我认为您已经接受了错误(且未格式化)的答案(它仅 打印 第一个元素,即 x 和 y 坐标列表中的 x 坐标,即完全错误)。请不要接受错误的答案。