Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import os# Function to display the main menudef display _ menu ( ) : print ( Store XYZ Inventory Management System ) print (
import os# Function to display the main menudef displaymenu: printStore XYZ Inventory Management System" print Add an Item to the Inventory." print Remove an Item from the Inventory." print Update an Item's Information." print Display a specific Items Information." print Exit"# Function to add an item to the inventorydef additem: # Function to validate ID def validateidid: if lenid or id or not id:isalpha or not id:isdigit: return False return True # Function to validate name def validatenamename: # Add your validation code here if lenname: return False return True # Function to validate category def validatecategorycategory: # Add your validation code here if lencategory: return False return True # Function to validate quantity def validatequantityquantity: # Add your validation code here try: quantity intquantity if quantity : return False except ValueError: return False return True # Function to validate unit price def validateunitpriceprice: # Add your validation code here try: price floatprice if price : return False except ValueError: return False return True # Function to validate supplier email def validatesupplieremailemail: # Add your validation code here if @ not in email or not in email: return False return True # Function to validate item details def validatedetailsdetails: # Add your validation code here if lendetails: return False return True # Collect item information from the user id inputEnter the ID of the item format: XYZ: if not validateidid: printInvalid ID format." return name inputEnter the name of the item: if not validatenamename: printInvalid name." return category inputEnter the category of the item: if not validatecategorycategory: printInvalid category." return quantity inputEnter the quantity of the item: if not validatequantityquantity: printInvalid quantity." return unitprice inputEnter the unit price of the item: if not validateunitpriceunitprice: printInvalid unit price." return supplieremail inputEnter the supplier email of the item: if not validatesupplieremailsupplieremail: printInvalid supplier email." return details while True: detail inputEnter a detail for the item press Enter to finish: if detail : break if not validatedetailsdetail: printInvalid detail." continue details.appenddetail # Add item to the inventory file with openinventorytxta as file: file.writefidnamecategoryquantityunitpricesupplieremailjoindetails
printItem added successfully."# Function to remove an item from the inventorydef removeitem: # Collect item ID from the user id inputEnter the ID of the item to remove: # Check if item exists in inventory file items with openinventorytxtr as file: for line in file: if line.stripsplit id: items.appendlinestrip if not items: printItem not found." return printItem found with the following information:" for item in items: printitem confirm inputAre you sure you want to remove this item? yesno: if confirm.lower "yes": with openinventorytxtw as file: for item in items: if item.stripsplit id: file.writefitem
printItem removed successfully." else: printRemoval cancelled."# Function to update an item's informationdef updateitem: # Collect item ID from the user id inputEnter the ID of the item to update: # Check if item exists in inventory file items with openinventorytxtr as file: for line in file: if line.stripsplit id: items.appendlinestrip if not items: printItem not found." return printItem found with the following information:" for item in items: printitem # Display update menu print
Update Menu:" print Update Name" print Update Category" print Update Quantity" print Update Unit Price" print Update Supplier Email" print Update Item Details" # Collect user choice choice inputEnter your choice: if choice : newname inputEnter the new name: items itemssplit newname itemssplit elif choice : newcategory inputEnter the new category: items itemssplit itemssplitsplit newcategory itemssplit elif choice : newquantity inputEnter the new quantity: items itemssplit newquantity itemssplit elif choice : newprice inputEnter the new unit price: items itemssplit newprice itemssplit elif choice : newemail inputEnter the new supplier email: items itemsrsplit newemail elif choice : newdetails while True: detail inputEnter a new detail for the item press Enter to finish: if detail : break newdetails.appenddetail items itemssplit itemssplitjoinnewdetails else: printInvalid choice." return with openinventorytxtw as file: for item in items: file.writefitem
printItem information updated successfully."# Function to display item informationdef displayiteminfo: # Display submenu printDisplay Menu:" print Display all items information." print Display all items information sorted by Quantity." print Display a specific items information based on the ID # Collect user choice choice inputEnter your choice: if choice : with openinventorytxtr as file: for line in file: printlinestrip elif choice : sortorder inputSort by Quantity a ascending, d descending: with openinventorytxtr as file: lines file.readlines lines.sortkeylambda x: intxstripsplit reversesortorder.lowerd for line in lines: printlinestrip elif choice : id inputEnter the ID of the item: with openinventorytxtr as file: for line in file: if line.stripsplit id: printlinestrip return printItem not found." else: printInvalid choice."# Main functiondef main: while True: displaymenu choice inputEnter your choice : if choice : additem elif choice : removeitem elif choice : updateitem elif choice : displayiteminfo elif choice : printExiting program..." break else: printInvalid choice. Please enter a number between and # Entry point of the programif namemain: main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started