I am trying to solve the practical problem of chapter 5 Automate the Boring Stuff. I am stuck here, I tried everything but again and again, it shows SyntaxError on line 17, I checked on the syntax of if statement and I think it is perfectly fine, Can anyone help me here?
def displayInventory(inventory):
print("Inventory:")
total=0
for k,v in inventory.items():
print(str(v)+" "+str(k))
total+=int(v)
print("Total number of itmes: "+str(total))
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
displayInventory(stuff)
def addToInventory(inventory, addedItems):
for i in range(len(addedItems):
if str(addedItems[i]) in inventory :
inventory[str(addedItems[i])] += 1
else:
inventory.setdefault(addedItems[i],1)
inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
addToInventory(inv,dragonLoot)s
displayInventory(inv)
addToInventory(tuff,dragonLoot)
displayInventory(stuff)
Aucun commentaire:
Enregistrer un commentaire