Question: class InventoryManager: def _ _ init _ _ ( self ) : self.inventory = Inventory ( ) def run ( self ) : while True:

class InventoryManager:
def __init__(self):
self.inventory = Inventory()
def run(self):
while True:
print("
Available commands:")
print("1. Add Item")
print("2. Remove Item")
print("3. View Inventory")
print("4. Exit")
command = input("Enter command: ")
if command =="1":
name = input("Enter item name: ")
quantity = validated_integer_input("Enter quantity: ")
self.inventory.add_item(Item(name, quantity))
elif command =="2":
name = input("Enter item name: ")
quantity = validated_integer_input("Enter quantity: ")
self.inventory.remove_item(name, quantity)
elif command =="3":
self.inventory.view_inventory()
elif command =="4":
break
def validated_integer_input(prompt):
while True:
try:
return int(input(prompt))
except ValueError:
print('Invalid input, please enter an integer.')

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 Programming Questions!