Compoter Science Final Project
Compoter Science Final Project
CERTIFICATE
Signature:
Date:
Page 2 of 20
ACKNOWLEDGEMENT
Page 3 of 20
Index
02. Acknowledgement 03
03. Title 05
04. Introduc on 06
06. Working 07
09. References 20
10
Page 4 of 20
Page 5 of 20
Introduc on
This Python program is a vegetable shop management system that enables owners to manage
inventory and customers to place orders. It provides features like viewing vegetables, upda ng stock,
placing orders, and genera ng bills. The program uses a MySQL database to store and manage
inventory data and presents output through plain console prints instead of tabular forma ng.
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.
Page 6 of 20
Refine the program by ensuring proper flow, handling excep ons, and displaying clear
messages for users.
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.
Page 7 of 20
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.
Page 8 of 20
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()
Page 9 of 20
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:
Page 10 of 20
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:
Page 11 of 20
print("4. Update Vegetable Info")
if choice == '1':
veg_id = name[:3]
try:
cursor.execute(
conn.commit()
except mysql.connector.IntegrityError as e:
if cursor.fetchone():
conn.commit()
else:
Page 12 of 20
elif choice == '3':
if cursor.fetchone():
conn.commit()
else:
if cursor.fetchone():
conn.commit()
else:
break
else:
conn.close()
Page 13 of 20
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:
Page 14 of 20
return "1"
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("___________________________________________________________________________
________________")
Page 15 of 20
name = input("Enter the vegetable name: ")
choose_vegetable(name, quantity)
print("___________________________________________________________________________
________________")
show_cart()
print("___________________________________________________________________________
________________")
generate_bill()
print("___________________________________________________________________________
________________")
update_vegetables()
print("___________________________________________________________________________
________________")
print("___________________________________________________________________________
________________")
exit_shop()
print("___________________________________________________________________________
________________")
break
else:
Page 16 of 20
print("___________________________________________________________________________
________________")
print("6. Exit")
if choice == '1':
show_vegetables()
print("___________________________________________________________________________
________________")
choose_vegetable(name, quantity)
print("___________________________________________________________________________
________________")
show_cart()
print("___________________________________________________________________________
________________")
generate_bill()
print("___________________________________________________________________________
________________")
Page 17 of 20
elif choice == '6':
exit_shop()
print("___________________________________________________________________________
________________")
break
if __name__ == "__main__":
main()
Program Run
Page 18 of 20
Page 19 of 20
References
Page 20 of 20