asked 137k views
4 votes
Python python python

pls answer it in 2 hours!! thank you
very important
You are required to write program to manage a shopping list for
the family.
The family wants to have a list of all the products

asked
User Aryaman
by
7.9k points

1 Answer

4 votes

Answer:

class ShoppingList:

def __init__(self):

self.products = []

def add_product(self, product):

self.products.append(product)

def remove_product(self, product):

if product in self.products:

self.products.remove(product)

else:

print(f"{product} is not in the shopping list.")

def view_list(self):

print("Shopping List:")

for product in self.products:

print(product)

def clear_list(self):

self.products = []

def check_off(self, product):

if product in self.products:

print(f"Checking off {product} from the shopping list.")

# Perform any additional actions for checking off a product

else:

print(f"{product} is not in the shopping list.")

# Example usage:

shopping_list = ShoppingList()

# Add products to the shopping list

shopping_list.add_product('Apples')

shopping_list.add_product('Milk')

shopping_list.add_product('Bread')

# View the shopping list

shopping_list.view_list()

# Remove a product from the shopping list

shopping_list.remove_product('Milk')

# View the updated shopping list

shopping_list.view_list()

# Check off a product from the shopping list

shopping_list.check_off('Bread')

# Clear the shopping list

shopping_list.clear_list()

# View the empty shopping list

shopping_list.view_list()

Python python python pls answer it in 2 hours!! thank you very important You are required-example-1
answered
User Cyassin
by
8.0k points

No related questions found