Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please explain what each part of code does = NE 4 5 6 1 def loadInventory(): 2 - fr = open(storeInventory.txt, 3 mi more r)

image text in transcribedimage text in transcribedimage text in transcribedplease explain what each part of code does

= NE 4 5 6 1 def loadInventory(): 2 - fr = open("storeInventory.txt", 3 mi more "r") #open file in read mode and get file handler fr inventoryDict = {} for line in fr: if line != ' ': 7 currentline = line.split(",") inventoryDict[currentline[@]] = [ int(currentline[1]), float(currentline[2]) ] return inventoryDict 8 9 10 6 11 12 13 14 16 17 - 15 - def updateInventory(inventoryDict): f = open("storeInventory.txt", "W") for key, value in inventoryDict.items(): f.write('%s,%d %f ' % (key, value[@], value[1])) 18 19 20 22 21 def display Inventory(inventoryDict): print("The current inventory is: ") for key, value in inventoryDict.items(): print 25 f"\tItem: {key), Amount Remaining: {value[0]}, Item Cost: {value[1]}" ) print() 23 O 24 - 26 27 28 29 30 def searchItem(inventoryDict, item): for key, value in inventoryDict.items(): if item key: print f"\tItem: {item}, Amount Remaining: {value[@]},Item Cost: {value[1]} " 31 A 32 = 33 O 34 == 35 36 37 return 1 print('Item was not found in Inventory.') return 38 39 40 41 42 == 43 44 45 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 != : 46 47 48 49 50 51 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 52 53 54 55 while itemQuantity ').capitalize() while choice != 'Exit': if choice == 'Search': 86 E while True: item = input 88 "Enter the item name you want to search: ").capitalize() searchFlag = searchItem(inventoryDict, item) 90 E if searchFlag == 0: chois - input || "Do you want to search an item. Enter Yes/No: 93 ).capitalize() if searchFlag -- 1 or chois == 'No': break 96 = elif choice == 'Purchase': 97 - while True: 98 item = input("Enter item to be purchased:").capitalize() purchaseFlag = PurchaseItem(inventoryDict, item) if purchaseFlag == 0: choice - input 102 || "Do you want to purchase an item. Enter Yes/No: ).capitalize() if purchaseFlag == 1 or choice == 'No': 105 break 106 A elif choice == 'Display': display Inventory(inventoryDict) 108 E else: print('Please enter a valid command.') 92 94 95 99 100 D 101 O 103 104 107 109 110 111 O 112 print( "Enter your choice of operation Search \t to search an item Purchase \t to purchase an item Display It to display the current inventory In Exit It to exit the program" ) choice = input('>').capitalize() 113 114 115 = 116 print("Goodbye.") main() 117

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Explain the relationship of job design to employee contributions.

Answered: 1 week ago