0% found this document useful (0 votes)
5 views

Worksheet1 Python

The document outlines a Python program designed to manage an e-commerce shopping cart, allowing users to add, remove, and view products along with their costs. It utilizes list operations such as append() and insert() to manipulate the cart and calculate the total cost of items. The program prompts users for various actions in a loop until they choose to exit.

Uploaded by

MRIGAANK JASWAL
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)
5 views

Worksheet1 Python

The document outlines a Python program designed to manage an e-commerce shopping cart, allowing users to add, remove, and view products along with their costs. It utilizes list operations such as append() and insert() to manipulate the cart and calculate the total cost of items. The program prompts users for various actions in a loop until they choose to exit.

Uploaded by

MRIGAANK JASWAL
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
You are on page 1/ 6

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


WORKSHEET1

Student Name: Mrigaank Jaswal UID: 22BCS14681


Branch: CSE Section/Group:22BCS_KRG-704 ‘B’
Semester: 4th Date of Performance: 20/2/2024
Subject Name: NMO using Python Subject Code: 22CSH-259

Aim: Imagine you are building an e-commerce platform. Discuss how you would use
lists to manage a user's shopping cart. Explain how you could add items to the cart,
remove items, and calculate the totla cost of the items. Use Following terms:Data
structure: List operation:A. append()B. insert().

S/W Requirement: Python, VS Code.

Source Code:
print("----------Welcome To Ecommerce Cart Manager-----------")

cart = []

cost = []

while True:

num = int(input("Enter Your Choice\n1. Add New Product in the List\n2. Append another item in the
cart at a particular place\n3. Search a Product in the cart\n4. Check what your cart contains\n5. Total
Cost of the items in the cart\n6. Remove an item\n"))

if num == 1:

n = int(input("Enter number of products\n"))

for i in range(n):

s = input("Enter product name\n")


1
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
c = int(input("Enter product cost\n"))

cart.append(s)

cost.append(c)

elif num == 2:

pos = int(input("Enter the position where you want to add the product\n"))

s = input("Enter product name\n")

c = int(input("Enter product cost\n"))

cart.insert(pos, s)

cost.insert(pos, c)

elif num == 3:

s2 = input("Enter product to search\n")

if s2 in cart:

index = cart.index(s2)

print("Product Details:\n")

print("Product = ", cart[index], " Cost = ", cost[index], "\n")

else:

print("Product not found!!\n")

elif num == 4:

for i in range(len(cart)):

print("Product = ", cart[i], " Cost = ", cost[i])

2
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
print()

elif num == 5:

total_cost = sum(cost)

print("Total cost = ", total_cost)

print()

elif num == 6:

s = input("Enter product to remove from cart\n")

if s in cart:

index = cart.index(s)

del cart[index]

del cost[index]

print("Product Deleted from cart\n")

else:

print("Product not found!!\n")

else:

print("Invalid Choice\n")

a = int(input("Enter 1 to continue and 0 to exit!\n"))

if a == 0:

break

3
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

print("Thank You for using our services")

OUTPUT:

4
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like