Hi I am a beginner in python and I am currently using Automate the boring stuff with python. This is my second book learning python. I practiced doing this code (transferring items in list to a dictionary) my code worked the way I wanted it to work but there is a 'none' at the bottom. Can someone enlighten my tiny brain on how to fix this please?
def addToInventory(inventory, addedItems):
for i in addedItems:
if i == 'gold coin':
inventory['gold coin'] += 1
else:
inventory.setdefault(i, 0)
inventory[i] += 1
print('Inventory:')
total_item = 0
for k, v in inventory.items():
print(str(v) + ' ' + k)
total_item += v
print('\nTotal number of items: ' + str(total_item))
inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
print(addToInventory(inv, dragonLoot))
This is the result: https://i.stack.imgur.com/fP1Ol.png