这段代码在检查时出现了缩进错误。我知道这种情况经常发生,但实例位于两个for循环之间,因为我需要引用两个不同的列表。
我甚至还没有数据集,但它至少应该报告语法是正确的。代码相当简单。我想要在建筑物中自动放置包裹,我想通过将最大的包裹放在最小空间的地方来实现这一点。
到目前为止,我使用的所有输入都是字典,因为我也需要知道我引用的是哪个书架。我就差这么一点就把它变成列表了,而且对格式化非常严格。
inv = maxkey["Inventory"]是错误发生的那一行。我不知道如何修复它。我是否应该对此项目使用列表?逻辑上有缺陷吗?有没有我忘了的括号?如果这只是我的疏忽,请让我知道。有关详细信息,请与我联系。
def loadOrder(inProd, units, loc, pref, shelves):
items = len(inProd)
while items > 0
# What is the biggest package in the list?
mxw = 0 # Frontal area trackers
BoxId = {} # Identifies what is being selected
for p in inProd:
if p["Height"]*p["Width"] > mxw:
mxw = p["Width"]*p["Height"]
BoxId = p
else:
pass
# What is the location with the least amount of space?
maxi = 0.001
maxkey = {}
for key in loc:
if key["Volume Efficiency"] > maxi and key["Width"] > mxw/BoxId["Height"]:
maxi = key["Volume Efficiency"]
maxkey = key
else:
pass
maxkey["Inventory"].append(BoxId)
weight = 0
volTot = 0
usedL = 0
inv = maxkey["Inventory"]
for k in inv:
weight = k['Weight']+weight
vol = k['Height']*k['Width']*k['Depth']+volTot
usedL = k['Width']+usedL
maxkey["Volume Efficiency"] = volTot/(maxkey['Height']*maxkey['Weight']*maxkey['Depth'])
maxkey['Width Remaining'] = usedL
maxkey['Capacity Remaining'] = weight
del inProd[BoxId]
items = len(inProd)
return [inProd, units, loc, pref, shelves]发布于 2020-06-20 03:09:05
函数定义中的缩进应如下所示:
def function-name():
<some code>
<return something>此外,您还错过了while循环后的:条件。
应该是while items > 0:
发布于 2020-07-01 11:54:59
而且不应该混合使用制表符、和空格来进行缩进。标准的缩进方式是4个空格。你可以在PEP 8中看到更多。
https://stackoverflow.com/questions/62474948
复制相似问题