int在for循环的2d数组中不可调用/不可下标

时间:2018-08-14 17:21:40

标签: python python-3.x

这是我认为与错误相关的代码部分。成本是一个值,唯一代码每次都会更改

dailyorders = []
uniquecode = 0
orders = [uniquecode, cost]
dailyorders.append(orders)

dailytakings = 0
print (dailyorders)
for f in range (0, len(dailyorders)):
    dailytakings = dailytakings + dailyorders[f[1]]

如果“ [f [1]]”使用方括号,则错误代码将显示以下内容。

Traceback (most recent call last):
File "C:/Users/JD/AppData/Local/Programs/Python/Python36-32/menu.py", line 
58, in <module>
dailytakings = dailytakings + dailyorders[f[1]]
TypeError: 'int' object is not subscriptable

如果是[[f(1)]”,则为

Traceback (most recent call last):
File "C:/Users/JD/AppData/Local/Programs/Python/Python36-32/menu.py", line 
58, in <module>
dailytakings = dailytakings + dailyorders[f(1)]
TypeError: 'int' object is not callable

1 个答案:

答案 0 :(得分:0)

要按日顺序访问元素1,请在使用范围计数器后移动索引参考。

dailyorders = []
uniquecode = 0
orders = [uniquecode, cost]
dailyorders.append(orders)

dailytakings = 0
print (dailyorders)
for f in range (0, len(dailyorders)):
    dailytakings = dailytakings + dailyorders[f][1]