0% found this document useful (0 votes)
33 views5 pages

Python 1

Uploaded by

mutimbajames82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

Python 1

Uploaded by

mutimbajames82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

QUESTION 1

class Product:
def __init__(self, name, price, quantity, category):
[Link] = name
[Link] = price
[Link] = quantity
[Link] = category

def __str__(self):

return f"Product Name: ${[Link]:.2f} (Quantity: {[Link]},


Category: {[Link]})"

if __name__ == "__main__":

product1 = Product("Laptop", 999.99, 10, "Electronics")


print(product1)
class Product:
def __init__(self, name, price, quantity, category):
[Link] = name
[Link] = price
[Link] = quantity
[Link] = category

def __str__(self):
return f"Name: {[Link]}, Price: {[Link]}, Quantity:
{[Link]}, Category: {[Link]}"

class Inventory:
def __init__(self):
[Link] = []

def add_product(self, product):


[Link](product)

def update_product(self, name, price, quantity):


for product in [Link]:
if [Link] == name:
[Link] = price
[Link] = quantity
return f"Updated {name} to Price: {price}, Quantity:
{quantity}"
return f"Product {name} not found."

def display_products(self):
if not [Link]:
print("No products in inventory.")
for product in [Link]:
print(product)

def find_product(self, name):


for product in [Link]:
if [Link] == name:
return product
return f"Product {name} not found."

def total_inventory_value(self):
total_value = sum([Link] * [Link] for product in
[Link])
return total_value

if __name__ == "__main__":
inventory = Inventory()

inventory.add_product(Product("Laptop", 999.99, 10, "Electronics"))


inventory.add_product(Product("Mouse", 25.99, 50, "Electronics"))

print("Current Inventory:")
inventory.display_products()
print(inventory.update_product("Laptop", 899.99, 8))

print(inventory.find_product("Mouse"))

print(f"Total Inventory Value: ${inventory.total_inventory_value():.2f}")


class Product:
def __init__(self, name, price, quantity, category):
[Link] = name
[Link] = price
[Link] = quantity
[Link] = category

def update_price(self, new_price):


[Link] = new_price

def update_quantity(self, new_quantity):


[Link] = new_quantity

def get_total_value(self):
return [Link] * [Link]

class Inventory:
def __init__(self):
[Link] = []

def add_product(self, product):


[Link](product)

def display_inventory(self):
for product in [Link]:
print(f"Name: {[Link]}, Price: {[Link]}, Quantity:
{[Link]}, Category: {[Link]}")

def find_product(self, name):


for product in [Link]:
if [Link] == name:
return product
return None

def calculate_total_value(self):
total_value = sum(product.get_total_value() for product in
[Link])
return total_value

inventory = Inventory()

inventory.add_product(Product("Laptop", 999.99, 10, "Electronics"))


inventory.add_product(Product("Chair", 49.99, 20, "Furniture"))
inventory.add_product(Product("Notebook", 2.99, 100, "Stationery"))
inventory.add_product(Product("Pen", 1.49, 200, "Stationery"))

print("Current Inventory:")
inventory.display_inventory()

laptop = inventory.find_product("Laptop")
if laptop:
laptop.update_price(899.99)
laptop.update_quantity(8)
updated_laptop = inventory.find_product("Laptop")
if updated_laptop:
print(f"\nUpdated Product Details: Name: {updated_laptop.name}, Price:
{updated_laptop.price}, Quantity: {updated_laptop.quantity}, Category:
{updated_laptop.category}")

total_value = inventory.calculate_total_value()
print(f"\nTotal Value of Inventory: ${total_value:.2f}")

You might also like