Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # addToInventory.py
- # written by yuxin.meng on Dec 30th in 2017.
- # e-mail: mengyuxin@hotmail.com
- def addToInventory(inventory, addedItems):
- # your code goes here
- for i in range(len(addedItems)):
- k = addedItems[i]
- inventory.setdefault(k, 0)
- inventory[k] += 1
- return inventory
- def displayInventory(inventory):
- print('Inventory:')
- item_total = 0
- for k, v in inventory.items():
- print(str(v) + ' ' + k)
- item_total += v
- print('Total number of items: ' + str(item_total))
- inv = {'gold coin': 42,
- 'rope': 1}
- dragonLoot = ['gold coin',
- 'dagger',
- 'gold coin',
- 'gold coin',
- 'ruby']
- inv = addToInventory(inv, dragonLoot)
- displayInventory(inv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement