如何修复TypeError: 'list' object cannot be interpreted as an integer
?不确定如何解决此错误。不要通过'list'对象获得什么意思不能被解释为整数
def minmult(n,d):
m = [[0 for x in range(n)] for x in range(n)]
s = [[0 for x in range(n)] for x in range(n)]
for i in range(1, n):
m[i][i] = 0
s[i][i] = 0
for diagonal in range(1, n-1):
m[i][j] = sys.maxsize
for i in range(n-diagonal):
j=i+diagonal
temp = m[i][k] + m[k+1][j] + d[i-1]*d[k]*d[j]
if temp < m[i][j]:
m[i][j] = q
s[i][j]=k
pprint(m)
pprint(s)
return m[1][n-1]
array=[10,4,5,20,2,50]
size = len(array)
print(str(minmult(array,size)))
答案 0 :(得分:0)
错误在这一行:
m = [[0 for x in range(n)] for x in range(n)]
由于您将n
作为列表传递给minmult
,而range
需要一个整数,因此您收到错误。
正如评论所说,并且在编写代码时,您希望将调用更改为:
minmult(size,array)
没有理由传递数组的大小,因为你可以在函数中确定它...