为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

呼啦一阵风 2021-05-14 14:23:44
我认为这是错误代码的相关部分。成本是一个价值,并且唯一代码每次都会更改dailyorders = []uniquecode = 0orders = [uniquecode, cost]dailyorders.append(orders)dailytakings = 0print (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 回答

?
慕森王

TA贡献1777条经验 获得超3个赞

要按日顺序访问元素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]


查看完整回答
反对 回复 2021-05-25
  • 1 回答
  • 0 关注
  • 131 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信