2016-02-20 56 views
0
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函數時收到語法錯誤。我無法確定這段代碼有什麼問題。Python語法無效定義函數

+1

什麼是確切的錯誤? –

+0

請在將來更仔細地校對你的代碼。 – TigerhawkT3

回答

2

函數中最後一次調用print時缺少右括號。另外,在定義代碼之前,您在展示的代碼中使用名稱item_total

一般來說:如果出現奇怪的語法錯誤 - 請查看上一行。