0% found this document useful (0 votes)
11 views4 pages

PPL - Assignment No 12

The document outlines a Python program that defines a STORE class to manage products, including their codes, names, and prices. It provides a menu-driven interface for users to display products, add or remove items from a cart, view the cart, and generate a bill. The program includes various methods for product management and user interaction, demonstrating basic object-oriented programming concepts.

Uploaded by

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

PPL - Assignment No 12

The document outlines a Python program that defines a STORE class to manage products, including their codes, names, and prices. It provides a menu-driven interface for users to display products, add or remove items from a cart, view the cart, and generate a bill. The program includes various methods for product management and user interaction, demonstrating basic object-oriented programming concepts.

Uploaded by

digiworksoft2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment No.

12

Problem Statement: Create class STORE to keep track of Products ( Product Code, Name
and price). Display menu of all products to user. Generate bill as per

Program with Output


class Product:
def_init_(self, product_code, name, price):
self.product_code = product_code
self.name = name
self.price = price
class store:
def_init_(self):
self.product list = []
self.cart = []
def add (self, product):
self.product_list.append (product)
def display (self):
for product in self.product_list:
print(f'{product.product_code}\t{product.name}\t{product.price}')
def add to cart (self, product):
for item in self.product_list:
if item.product_code == product:
self.cart.append(item)
print("Added")
return
print("Item not present in store")
def remove_from_cart(self, product):
for item in self.cart:
if item.product_code == product:
self.cart.remove(item)
print(f'{item.name} removed from cart')
return
print("No product found in cart with this code")
def generate bill (self):
amount = 0
for product in self.cart:
amount += product.price
print (f'Total bill amount is {amount}')
def display_cart (self):
for item in self.cart:
print(f'{item.name}')
s = Store()
s.add(Product (1, "Milk",20))
s.add(Product (2, "Wheat",300))
s.add(Product (3, "Chocos", 150))
s.add (Product (4, "Biscuit", 10))
print("1.Display Products\n2.Add product to cart\n3.Remove Product\n4.View cart\n5.Generate
Bill\n6.Exit ")
choice = int(input("Enter your choice: "))
if choice == 1:
s.display()
elif choice == 2:
code = int(input("Enter product code: "))
s.add_to_cart(code)
elif choice == 3:
code = int(input("Enter product code: "))
s.remove from cart (code)
elif choice == 4:
s.display_cart()
elif choice == 5:
s.generate_bill()
else:
print("Enter a valid choice")

Output :
Display Products
2.Add product to cart
3. Remove Product
4. View cart
5.Generate Bill
6. Exit
Enter your choice: 1
1 Milk 20
2 Wheat 300
3 Chocos 150
4 Biscuit 10
1. Display Products
2. Add product to cart
3. Remove Product
4. View cart
5. Generate Bill
6. Exit
Enter your choice: 2
Enter product code: 2
Added
1. Display Products
2. Add product to cart
3. Remove Product
4. View cart
5. Generate Bill
6. EXIT

You might also like