我在尝试用Python。我想将一个列表(plateau)分成几个列表(L[I]),但我有以下错误消息:
File "C:\Users\adescamp\Skycraper\skycraper.py", line 20, in <module>
item = plateau[debut:fin]
TypeError: slice indices must be integers or None or have an __index__ method
相关行是带有item = plateau[debut:fin]
的行
from math import sqrt
plateau = [2, 3, 1, 4, 1, 4, 2, 3, 4, 1, 3, 2, 3, 2, 4, 1]
taille = sqrt(len(plateau))
# Division en lignes
L = []
i = 1
while i < taille:
fin = i * taille
debut = fin - taille
item = plateau[debut:fin]
L.append(item)
i += 1
您的
debut
和fin
值是浮点值,而不是整数,因为taille
是浮点值。将这些值改为整数:
或者,将
taille
设为整数:相关问题 更多 >
编程相关推荐