The goal:
Create an application which manages an inventory of products. Create a product class which has a price, id, and quantity on hand. Then create an inventory class which keeps track of various products and can sum up the inventory value.
I figured out how to get a list of dictionaries, and then add up the price. My output isn't pretty, but before I continue, I would simply like general critique.
class Product:
def __init__(self, i, p, q):
self.identification = i
self.price = p
self.quantity = q
self.item_dictionary = {'ID: ': self.identification, 'Price: ': self.price, 'Quantity: ': self.quantity}
class Inventory:
def __init__(self):
self.identification, self.price_list, self.quantity_list = [], [], []
self.products = [
product_1.item_dictionary,
product_2.item_dictionary
] # Make list of item dictionaries
for i in self.products:
self.identification.append(i['ID: '])
self.price_list.append(i['Price: '])
self.quantity_list.append(i['Quantity: '])
# Make unique lists of ID, Price, and Quantity
print(sum(self.price_list))
product_1 = Product(32, 23, 2)
product_2 = Product(23, 65, 3)
inventory_1 = Inventory()
for i in self.products
andprint(...)
sections are not indented correctly. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information. \$\endgroup\$