SHARE
TWEET

Untitled

a guest Jun 18th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def displayInventory(Inventory): #rpints out the whole inventory
  2.     print("Inventory:")
  3.     item_total = 0
  4.     for k, v in Inventory.items():
  5.         item_total = item_total + stuff.get(k,v)
  6.         print(k, v)
  7.     print("Total number of items: " + str(item_total))
  8.  
  9. def addToInventory(inventory, addedItems): #merges the dragonloot box into our stuff/inventory
  10.     for k in range(len(addedItems)):
  11.         inventory.setdefault(addedItems[k], 0) #creates empy keynames in the stuff/inventory dictionary
  12.         inventory(addedItems[k]) = inventory(addedItems[k]) + 1
  13.     return (inventory)
  14.  
  15. stuff = {"gold": 42, "rope": 1}
  16. dragonLoot = ["gold", "dagger", "gold", "gold", "ruby"]
  17. stuff = addToInventory(stuff, dragonLoot)
  18. displayInventory(stuff)
  19.      
  20. def displayInventory(Inventory): #rpints out the whole inventory
  21.     print("Inventory:")
  22.     item_total = 0
  23.     for k, v in Inventory.items():
  24.         item_total = item_total + stuff.get(k,v)
  25.         print(k, v)
  26.     print("Total number of items: " + str(item_total))
  27.  
  28. def addToInventory(inventory, addedItems): #merges the dragonloot box into our stuff/inventory
  29.     for k in range(len(addedItems)):
  30.         inventory.setdefault(addedItems[k], 0) #creates empy keynames in the stuff/inventory dictionary
  31.         inventory[addedItems[k]] = inventory[addedItems[k]] + 1
  32.     return (inventory)
  33.  
  34. stuff = {"gold": 42, "rope": 1}
  35. dragonLoot = ["gold", "dagger", "gold", "gold", "ruby"]
  36. stuff = addToInventory(stuff, dragonLoot)
  37. displayInventory(stuff)
  38.      
  39. inventory[addedItems[k]] = inventory(addedItems[k]) + 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top