This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def display_Inventory(inventory): | |
| print('Inventory') | |
| for k, v in inventory.items(): | |
| print(v, k) | |
| print('Total number of items:' + ' ' + str(sum(inventory.values()))) | |
| def add_To_Inventory(inventory, added_Items): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def display_inventory(inventory): | |
| print('Inventory') | |
| for k, v in inventory.items(): | |
| print(v, k) | |
| print('Total number of items:' + ' ' + str(sum(inventory.values()))) | |
| def add_to_inventory(inventory, added_items): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_to_inventory(inventory, added_items): | |
| inventory['banana'] = 'phone' | |
| inventory[item] = inventory.get(item, 0) + 1 | |
| inv = {} | |
| dragonLoot = ['gold coin','dagger','gold coin','gold coin','ruby'] | |
| print(add_to_inventory(inv, dragonLoot)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_to_inventory(inventory,): | |
| inventory['banana'] = 'phone' | |
| inv = {} | |
| dragonLoot = ['gold coin','dagger','gold coin','gold coin','ruby'] | |
| print(add_to_inventory(inv, dragonLoot)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_to_inventory(inventory): | |
| inventory['banana'] = 'phone' | |
| inv = {} | |
| dragonLoot = ['gold coin','dagger','gold coin','gold coin','ruby'] | |
| print(add_to_inventory(inv)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_to_inventory(inventory): | |
| inventory = 'd' | |
| inv = '' | |
| add_to_inventory(inv) | |
| print(inv) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def append_twice_okay(a_list, val): | |
| """mutates argument.""" | |
| a_list.append(val) | |
| a_list.append(val) | |
| def append_twice_good(a_list, val): | |
| """returns new list.""" | |
| a_list = a_list + [val, val] | |
| return a_list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def append_twice_okay(a_list, val): | |
| """mutates argument.""" | |
| a_list.append(val) | |
| a_list.append(val) | |
| def append_twice_good(a_list, val): | |
| """returns new list.""" | |
| return a_list + [val, val] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pprint | |
| stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12} | |
| def displayInventory(inventory): | |
| print("Inventory:") | |
| item_total = 0 | |
| for k, v in inventory.items(): | |
| print(v, k) | |
| item_total += v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inventory = {'gold coin': 42, 'rope': 1} | |
| addedItems = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby'] | |
| for item in addedItems: | |
| inventory[item] += item | |
| print(inventory) |