Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, I want to create the following application in python, I have instructions and files to complete this Wizard inventory with file I/O and exceptions
Hi, I want to create the following application in python, I have instructions and files to complete this Wizard inventory with file I/O and exceptions bellow.
I appreciate the help. Thanks!
Programming Assignment: Wizard Inventory with File I/O and Exceptions Problem Statement: In this assignment, you will modify the starter program, wizard_inventory-py, so that it works with files and handles errors with proper exception handling. Specifically, modify the program in the following steps: Step 1: Write a read_inventory function that reads and returns the inventory as a list of lists from the given csv file (wizard-items.csv). Step 2: Write a write_inventory function that takes an argument which is a list of lists and writes the contents to the same csv file (wizard-items.csv). Step 3: Modify the rest of the code to initialize the inventory by reading it from the wizard-items.csv file and writing to that csv file every time any changes are done to the inventory by the user. So that when user makes changes to the inventory, exits the program and runs it again, the changes are seen in the newly read inventory. Step 4: Add exception handling to the delete_item and edit_item methods so that a. if user enters a non-integer value for the index, program doesn't crash instead prints specific feedback: ********** Please enter a valid integer********** b. if user enters an out of range index value, program doesn't crash instead prints ********** Please enter an index between 1 and n ********* (where n is the number of items in the inventory). See the sample run 2 below. Step 5. Add exception handling to the read and write functions so that if there is any error in opening, reading from or writing to the file, program doesn't crash instead prints specific feedback (e.g. *********** Error reading from wizard-items.csv********** or " ******** Error writing to wizard-items.csv*** ). See the sample run 3 below. Submit the program in La file with a name of the for first_last_wizard inventory.py. Make sure to add a block-comment at the start of the file that lists assignment title. class name, date, your name, and assignment description def list items (inventory): Function to display the list of items from the invetory' for i in range (len (inventory)): item = inventory[i] print(f"(i+1}. {item [1]} {item [0] .title()} ({item [2]})") print() def add_item(inventory): Function to add a new item to the invetory'' name = input("Name: ") color = input("Color: ") weight = int(input("Weight: ")) item = [] item.append(name) item.append(color) item.append (weight) inventory.append(item) print (name + " was added. ") def delete item (inventory): Function to delete an item from the invetory' index = int(input ("Number: ")) item = inventory.pop (index - 1) print(item [0] + was deleted. ") TI def edit_item_name (inventory): * Function to delete an item from the invetory!!! index = int(input("Number: ")) newName = input ("Enter updated name: ") File Edit Format Run def edit_item_name (inventory): Function to delete an item from the invetory'' index = int(input("Number: ")) newName = input ("Enter updated name: ") inventory[index - 1][0] = new Name print("Item number " + str(index) + " name was updated. ") def display_menu(): print("The Wizard Inventory List program") print() print("COMMAND MENU") print("list List all inventory items") print("add Add an item") print("del Delete an item") print("edit - Edit name of an item") print("exit Exit program") print() def main(): display_menu () inventory = [["wooden staff", "Brown", 30.0], ["wizard hat", "Black", 1.5], ["cloth shoes", "Blue", 5.3]] while True: command = input("Command: ") if command.lower() == "list": list items (inventory) elif command.lower() == "add" : - print("edit print("exit print() Edit name of an item") Exit program") def main() : display menu () inventory = [["wooden staff", "Brown", 30.0], ["wizard hat", "Black", 1.5), ["cloth shoes", "Blue", 5.3]] while True: Command = input ("Command: ") if command.lower() == "list": list_items (inventory) elif command.lower() "add" : add item (inventory) elif command.lower () "del": delete item (inventory) elif command.lower() "edit": edit item name (inventory) I elif command.lower() == "exit": break else: print("Not a valid command. Please try again. ") print("Bye!") == f 11 main ": name main() wizard-items - Saved - st Formulas Data Review View . % Conditional Formatti PZ Format as Table Cell Styles Number Alignment Styles Wooden Staff C D B 1 Wooden Brown 2 Wizard Ca Black 3 Cloak of Ir Black 1.5 10.2. 4 Scroll of U Blue 5 6 7 8 9 10 12 13Step 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