52.4k views
3 votes
write a program in python to create class store to keep track of products (product code, name and price). display menu of all products to user. generate bill as per order.___

1 Answer

5 votes

Final answer:

The question is about creating a Python class called 'Store' with methods to track products, display a product menu, and generate a bill.

Step-by-step explanation:

To create a class named Store in Python to keep track of products, you would define attributes for the product code, name, and price. Here is an example of how such a program might look, including functions to display a menu of products and generate a bill for the user's order.

class Store:
def __init__(self):
self.products = []

def add_product(self, code, name, price):
self.products.append({'code': code, 'name': name, 'price': price})

def display_menu(self):
print("Product Menu:")
for product in self.products:
print(f"{product['code']}: {product['name']} - ${product['price']}")

def generate_bill(self, order):
total = 0
print("Bill:")
for item in order:
for product in self.products:
if product['code'] == item:
print(f"{product['name']}: ${product['price']}")
total += product['price']
print(f"Total: ${total}")

# Example usage:
store = Store()
store.add_product('001', 'Apple', 0.99)
store.add_product('002', 'Bread', 2.49)
store.add_product('003', 'Milk', 1.99)

store.display_menu()
order = ['001', '003']
store.generate_bill(order)

This script defines the Store class with methods to add a product, display a menu of products, and generate a bill based on a given order. To use the class, we instantiate it, add some products, display the menu, and then pass a list of ordered product codes to generate a bill showing the items purchased and the total cost.

User AdamSchuld
by
8.0k points