0% found this document useful (0 votes)
8 views12 pages

Bakery Management System in Python

The Bakery Management System is a Python project that utilizes file handling to manage bakery product information, allowing users to add, view, search, update, and delete products from a text file. It features a user-friendly menu and demonstrates the use of Python's file operations without requiring a database. The system is ideal for learning data management through text files in Python.

Uploaded by

madhavbakshi98
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)
8 views12 pages

Bakery Management System in Python

The Bakery Management System is a Python project that utilizes file handling to manage bakery product information, allowing users to add, view, search, update, and delete products from a text file. It features a user-friendly menu and demonstrates the use of Python's file operations without requiring a database. The system is ideal for learning data management through text files in Python.

Uploaded by

madhavbakshi98
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

INTRODUCTION

The Bakery Management System is a basic Python


project that uses the concepts of file handling to
store and manage bakery product information. The
system maintains a simple text file in which each
product’s name and price are recorded. Using file
operations such as write, append, read, and
rewrite, the program allows users to add new
product details, delete existing products, and display
the complete bakery menu.
This project demonstrates how Python’s file
handling features can be used to create a small,
efficient data-management application without the
need for a database. It provides an easy way to keep
product records updated and ensures that the menu is
stored permanently in a file for future use. The
system is simple, user-friendly, and ideal for
learning how real-life data can be handled using text
files in Python.
Functions Used in the
Program
1. add_item():
o Purpose:To add a new bakery product (name + price)
to the file.
o Operations:
 Takes user input (name, price).
 Opens the file in append mode ("a")
 Writes a new line in the format:
item_name, price
 Confirms item addition.

2. view_items()
o Purpose:To display all bakery items stored in the file.
o Operations:
 Opens the file in **read mode ("r")
 Reads all lines using `.readlines()`.
 If file is empty, prints “No items found.”
 Splits each line into `name` and `price`.
 Prints the details in a formatted way.
 Handles **FileNotFoundError** if the file
doesn’t exist.
3. search_item()
o Purpose: To search for an item in the bakery list by its
name.
o Operations:
 Takes name input from user.
 Opens file in read mode.
 For each line, splits into `name, price`.
 Checks if lowercase names match.
 Displays details if found.
 If not found, prints “Item not found.”
4. update_price()
o Purpose: To update the price of an existing bakery
item.
o Operations:
 Takes item name as input.
 Reads all lines into a list.
 Rewrites the file using **write mode
("w")**.
 For each line:
 If name matches → writes updated
price.
 Else → writes old line.
 Prints whether update happened or
not.
5. delete_item()
o Purpose: To delete an item from the bakery list.
o Operations:
 Takes item name input.
 Reads all file lines.
 Opens file in **write mode ("w")**.
 Writes back only the lines that **do not match** the
given item name.
 If match found → sets deletion flag.
 Prints whether deletion happened or not.
6. Main Menu (while loop)
o Purpose: To provide a continuous, interactive menu-
driven interface.
o Operations:
 Displays menu choices.
 Takes choice input.
 Calls corresponding function.
 Exits only when user selects option **6**.

File Operations Used:


Operation Mode Meaning
open(FILE,’a’) Append Adds new data at
bottom of file
Open(FILE) or Read Reads entire file or
Open(FILE,’r’) line by line
Open(FILE,’w’) Write Rewrites file &
writes
readlines _ Reads entire file as
a list
split(“,”) _ Separates name
and price
strip() _ Removes newline
and spaces
Code
FILE = "[Link]"

def add_item():
name = input("Enter item name: ")
price = input("Enter price: ")
with open(FILE, "a") as f:
[Link](name + "," + price + "\n")
print("Item added.")

def view_items():
print("\n--- Bakery Items ---")
try:
with open(FILE, "r") as f:
data = [Link]()
if not data:
print("No items found.")
for line in data:
name, price = [Link]().split(",")
print(f"Name: {name}, Price: Rs.{price}")
except FileNotFoundError:
print("No records yet.")

def search_item():
key = input("Enter item name to search: ").lower()
found = False
try:
with open(FILE, "r") as f:
for line in f:
name, price = [Link]().split(",")
if [Link]() == key:
print("Found:", name, "Price: Rs.", price)
found = True
break
except FileNotFoundError:
pass
if not found:
print("Item not found.")
def update_price():
key = input("Enter item name to update: ").lower()
updated = False
items = []
try:
with open(FILE, "r") as f:
items = [Link]()
except FileNotFoundError:
print("No items found.")
return

with open(FILE, "w") as f:


for line in items:
name, price = [Link]().split(",")
if [Link]() == key:
new_price = input("Enter new price: ")
[Link](name + "," + new_price + "\n")
updated = True
else:
[Link](line)
print("Price updated." if updated else "Item not found.")

def delete_item():
key = input("Enter item name to delete: ").lower()
deleted = False
try:
with open(FILE, "r") as f:
items = [Link]()
except FileNotFoundError:
print("No items to delete.")
return

with open(FILE, "w") as f:


for line in items:
name, price = [Link]().split(",")
if [Link]() != key:
[Link](line)
else:
deleted = True
print("Item deleted." if deleted else "Item not found.")

# ---- MAIN MENU ----


while True:
print("\n--- Bakery Management System ---")
print("1. Add Item")
print("2. View Items")
print("3. Search Item")
print("4. Update Price")
print("5. Delete Item")
print("6. Exit")

ch = input("Enter choice: ")

if ch == "1":
add_item()
elif ch == "2":
view_items()
elif ch == "3":
search_item()
elif ch == "4":
update_price()
elif ch == "5":
delete_item()
elif ch == "6":
print("Exiting...")
break
else:
print("Invalid choice.")
OUTPUT
BIBLOGRAPHY
 Python official documentation ([Link])
 [Link]
 [Link]

You might also like