Question: Please explain how this code works please go over every function 1 2 3 4 5 pef loadinventory(): fr = open(storeInventory.txt, ||||) #open file in

 Please explain how this code works please go over every function1 2 3 4 5 pef loadinventory(): fr = open("storeInventory.txt", ||||"") #openfile in read mode and get file handler fr inventoryDict = {}

Please explain how this code works please go over every function

1 2 3 4 5 pef loadinventory(): fr = open("storeInventory.txt", ||||"") #open file in read mode and get file handler fr inventoryDict = {} for line in fr: if line != ' ': currentline = line.split(",") inventoryDict[currentline[@]] = [ int(currentline[1]), float(currentline[2]) ] return inventoryDict def updateInventory(inventoryDict): f = open("storeInventory.txt", "W") for key, value in inventoryDict. items(): f.write("%s,d,%f ' % (key, value[@], value[1])) 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 def display Inventory(inventoryDict): print("The current inventory is: ") for key, value in inventoryDict.items(): print f"\tItem: key), Amount Remaining: {value[@]},Item Cost: {value[1]}" print def searchitem(inventorydict, item): for key, value in inventoryDict.items(): if item == key: print f" titem: {item), Amount Remaining: {value[@]},Item Cost: {value[1]} " > return 1 print('Item was not found in Inventory.') return @ 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 def PurchaseItem(inventoryDict, item): for key in inventoryDict.keys(): if item == key: # if item is found gets its quantity and cost itemQuantity = inventoryDict[key][@] itemcost = inventoryDict[key][1] # if item still in inventory if itemQuantity != e: purchaseQuantity = int( | input("Enter number of item to be purchased: ")) # If quantity is entered bigger than available then take input again # loop is used to keep on taking input until less quantity is entered 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 while itemQuantity ').capitalize() while choice != 'Exit': if choice == 'Search': while True: item = input "Enter the item name you want to search: ").capitalize() searchFlag - searchItem(inventoryDict, item) if searchFlag == @: chois = input "Do you want to search an item. Enter Yes/No: ).capitalize() if searchFlag == 1 or chois == 'No': break elif choice == 'Purchase': while True: item = input("Enter item to be purchased:").capitalize() purchaseFlag = PurchaseItem(inventoryDict, item) if purchaseFlag == 0: choice = input "Do you want to purchase an item. Enter Yes/No: ).capitalize() if purchaseFlag == 1 or choice == 'No': break elif choice == 'Display": display Inventory(inventoryDict) else: print("Please enter a valid command.') print "Enter your choice of operation Search \t to search an item Purchase it to purchase an item Display it to display the current inventory Exit \t to exit the program" choice = input('>').capitalize() 114 115 116 117 118 119 120 print("Goodbye.") main() 121

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!