[英]Iterate over a list with floats, and use them in math equations
I am trying to iterate over a list with floats and calculate with the items in the lists, but I always get this:我正在尝试使用浮点数迭代列表并使用列表中的项目进行计算,但我总是得到这个:
list indices must be integers or slices, not float
列表索引必须是整数或切片,而不是浮点数
as you can see below, there are lists named t
, and sdt
which have the same length and are both floats:正如您在下面看到的,有名为
t
和sdt
的列表具有相同的长度并且都是浮点数:
for i in t:
if t[i] == t[0] or t[1] or t[2] or t[3]:
for i in t[0:4]:
rp1x = r+h
rp1y = sdt[i] - .5*(l-w)
print(rp1x, rp1y)
you are trying to use the items from your list as indices, you should use:您正在尝试将列表中的项目用作索引,您应该使用:
my_items = t[0:4]
for item in t:
if item in my_items:
for i in my_items:
rp1x = r+h
rp1y = sdt[i] - .5*(l-w)
print(rp1x, rp1y)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.