FF
FF
Signature:
Date:
ACKNOWLEDGEMENT
1. Understanding Requirements:
Begin by understanding the requirements of the VEGETABLE SHOP MANAGEMENT
APPLICATION.
Iden fy the key func onali es it should offer, such as displaying menus, placing orders,
viewing orders, and genera ng bills.
fetch_vegetables(): Loads the list of vegetables and their details (price, stock) into a
global dic onary.
show_vegetables(): Displays available vegetables along with their price and stock.
choose_vegetable(name, quan ty): Allows a user to add a vegetable to the cart and
reduces its stock accordingly.
show_cart(): Displays the items added to the cart along with their quan es and total
price.
generate_bill(): Provides a detailed bill of purchased items, including their quan ty,
price, and total amount
3. Owner-Specific Features
Ensure vegetable IDs are unique and validate entries before commi ng changes to the
database.
4. Customer-Specific Features
Access to Shop: Customers can browse available vegetables, add items to their cart, view the
cart, and generate a bill.
No Database Modifica ons: Customers can only interact with stock quan es for their
purchase
5. User Switching
login(): Determines if the user is an Owner or Customer based on their choice and login
creden als.
switch_user(): Switches between the Owner and Customer roles during run me
main():
Handles opera ons like showing vegetables, upda ng details, placing orders, and exi ng the
shop.
Key Features
Cart Management: Allows customers to select vegetables and tracks their purchases.
Role-Based Access: Dis nguishes func onali es between Owners and Customers.
#This program can be extended with features like payment integra on or online ordering
for a complete e-commerce system.
PROGRAM CODE
import mysql.connector
vegetables = {}
veg_id={}
cart = {}
def connect_to_db():
conn = mysql.connector.connect(
host="localhost",
user="root",
password="BILLU"
return conn
def create_database():
conn = connect_to_db()
cursor = conn.cursor()
cursor.execute("USE vegetable_shop")
veg_id VARCHAR(5),
name VARCHAR(50),
price FLOAT,
stock FLOAT
)""")
conn.commit()
conn.close()
def fetch_vegetables():
global vegetables
conn = connect_to_db()
cursor = conn.cursor()
cursor.execute("USE vegetable_shop")
result = cursor.fetchall()
conn.close()
def show_vegetables():
print("Available Vegetables:")
if name in vegetables:
vegetables[name]['stock'] -= quantity
else:
def calculate_total():
total = 0
return total
def show_cart():
if not cart:
else:
print("Your cart:")
def generate_bill():
print("Generating Bill...")
if not cart:
else:
print("Bill Details:")
def switch_user():
print("Switching user...")
new_user_type = login()
user_type = new_user_type
else:
def update_vegetables():
conn = connect_to_db()
cursor = conn.cursor()
cursor.execute("USE vegetable_shop")
while True:
if choice == '1':
veg_id = name[:3]
try:
cursor.execute(
conn.commit()
except mysql.connector.IntegrityError as e:
if cursor.fetchone():
conn.commit()
else:
if cursor.fetchone():
conn.commit()
else:
if cursor.fetchone():
conn.commit()
else:
break
else:
conn.close()
def exit_shop():
print("Thank you for visiting SHOBHA'S VEGETABLE SHOP. Have a great day!")
def login():
while True:
print("___________________________________________________________________________
________________")
if user_type == "1":
if password == owner_password:
return "1"
else:
print("Welcome, Customer!")
return "2"
else:
print("___________________________________________________________________________
________________")
if user_type == "1":
if password == owner_password:
else:
print("Welcome, Customer!")
return "2"
def switch_user():
print("Switching user...")
return login()
def main():
create_database()
fetch_vegetables()
user_type = login()
if user_type is None:
return
while True:
if user_type == "1":
print("7. Exit")
if choice == '1':
show_vegetables()
print("___________________________________________________________________________
________________")
choose_vegetable(name, quantity)
print("___________________________________________________________________________
________________")
show_cart()
print("___________________________________________________________________________
________________")
generate_bill()
print("___________________________________________________________________________
________________")
update_vegetables()
print("___________________________________________________________________________
________________")
print("___________________________________________________________________________
________________")
exit_shop()
print("___________________________________________________________________________
________________")
break
else:
print("6. Exit")
if choice == '1':
show_vegetables()
print("___________________________________________________________________________
________________")
choose_vegetable(name, quantity)
print("___________________________________________________________________________
________________")
show_cart()
print("___________________________________________________________________________
________________")
generate_bill()
print("___________________________________________________________________________
________________")
elif choice == '6':
exit_shop()
print("___________________________________________________________________________
________________")
break
if __name__ == "__main__":
main()