Satchel = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1}
def displayInventory(inventory, leftWidth, rightWidth):
print('INVENTORY'.center(leftWidth + rightWidth, '-'))
for k, v in inventory.items():
print(k.ljust(leftWidth, '.') + str(v).rjust(rightWidth))
item_total = int(item_total) + int(v)
print('Total number of items: ' + str(item_total)
displayInventory(Satchel, 15, 6)
调用displayInventory函数时收到语法错误。我很难确定这个代码有什么问题。你知道吗
函数中对
print
的最后一次调用缺少右括号。此外,在您显示的代码中,在定义名称之前使用的是名称item_total
。你知道吗一般来说:如果你得到一个奇怪的语法错误-看看上一行。你知道吗
相关问题 更多 >
编程相关推荐