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

Library Management Python

This document provides source code for a book shop management system project in Python. The source code includes functions for a book menu to add, update, delete, or view books; a sales module to record sales; and a customer menu to manage customer details. The code uses SQLite to create and connect to databases to store book, customer, and sales data. Key functions allow the user to add, update, delete and view book details as well as record sales and customer information to help a shopkeeper efficiently manage their bookstore operations.

Uploaded by

Kunnu Kunal
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)
162 views

Library Management Python

This document provides source code for a book shop management system project in Python. The source code includes functions for a book menu to add, update, delete, or view books; a sales module to record sales; and a customer menu to manage customer details. The code uses SQLite to create and connect to databases to store book, customer, and sales data. Key functions allow the user to add, update, delete and view book details as well as record sales and customer information to help a shopkeeper efficiently manage their bookstore operations.

Uploaded by

Kunnu Kunal
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/ 30

1.

Acknowledgment
2. Introduction to Python
3. Introduction to Project
4. Source Code
5. Output
6. Hardware & Software
Requirements
7. Bibliography
CERTIFICATE
This is to certify that Kunal Kumar
Sonkar of Std. XII-‘B’ has completed the
computer project on ‘Book Shop
Management System’ under the
guidance of his computer teacher Mr.
Maninder Singh.

………………………. ……………………….
Signature of Internal Signature of External

……………………………..
Signature of Principal
ACKNOWLEDGEMENT

I would like to express a deep sense of thanks and


gratitude to our Principal, Mrs. MILI SINHA, for her co-
ordination in extending every possible support for the
completion of this project and a sincere thanks to our
computer teacher Mr. Maninder Singh for guiding me
immensely through the course of my project. His
constructive advice and constant motivation have been
responsible for the successful completion of my project.

My sincere thanks to my parents for their motivation and


support. I must thank my group mates for their timely
help and support for the completion of this project.
INTRODUCTION TO
PYTHON
Python is developed by Guido van Rossum. Guido van
Rossum started implementing Python in 1989. Python is
a very simple programming language so even if you are
new to programming, you can learn python without
facing any issues.

FEATURES OF PYTHON PROGRAMMING:

1. Readable: Python is a very readable language.

2. Easy to Learn: Learning python is easy as this is an expressive and high-


level programming language, which means it is easy to understand the
language and thus easy to learn.

3. Cross-platform: Python is available and can run on various operating


systems such as Mac, Windows, Linux, UNIX, etc. This makes it a cross-
platform and portable language.

4. Open Source: Python is an open-source programming language.

5. Large standard library: Python comes with a large standard library that
has some handy codes and functions which we can use while writing code in
Python.

6. Supports exception handling: If you are new, you may wonder what an
exception is. An exception is an event that can occur during a program
exception and can disrupt the normal flow of a program. Python supports
exception handling which means we can write less error-prone code and can
test various scenarios that can cause an exception later on.
INTRODUCTION TO THE
PROJECT…
Book shop management system is a python and SQL based project.
This system is developed to manage the sales and inventory of books
in any book shop. It is used by shopkeepers to manage their store
using a computerized system. The system was developed and
designed to help the shopkeeper record every book purchase and keep
the inventory updated.

The different functions used in this project are:


1. Book Menu: It contains all the functions related to adding, viewing,
deleting or updating book list.

2. Sales module: It contains all functions related to sale of books, such


as keeping record of all the sales.

3. Customer Menu: It contains all the functions related adding,


updating, deleting or viewing customer details.

This program can help a shopkeeper to manage his Book Store more
conveniently and efficiently as compared to those without
computerized system.
Source code:
#BOOK-MANAGEMENT_SYSTEM
#IMPORTING sqlite3 PREBUILT LIBRARY IN THE PROJECT
import sqlite3
sql_connect = sqlite3.connect('bookmanagement.db')
cursor = sql_connect.cursor()
t=0
#To check if the tables exist or not and the accordingly create them if they don't
exist
try:
query = "SELECT * FROM bookdetails"
cursor.execute(query).fetchone
except:

create = "CREATE TABLE bookdetails (b_id int NOT NULL PRIMARY KEY,b_name
varchar(255) NOT NULL,author varchar(255), publication varchar(255), ISBN
int,price int, quantity int)"
cursor.execute(create)

try:
query2 = 'SELECT * FROM customerdetails'
cursor.execute(query2).fetchone
except:
createCust = "CREATE TABLE customerdetails (c_id int NOT NULL PRIMARY
KEY,c_name varchar(255) NOT NULL,c_address varchar(255), c_phone
varchar(10))"
cursor.execute(createCust)
try:
query3 = 'SELECT * FROM sales'
cursor.execute(query3).fetchone
except:
cursor.execute("CREATE TABLE sales (t_id int NOT NULL PRIMARY KEY, c_id int
NOT NULL, b_id int NOT NULL, date DATE NOT NULL, quantity int NOT NULL,
total_price int NOT NULL)")
def bookmenu():
#book details menu
print('Book Menu')
print('1.) Add a book')
print('2.) Update a book')
print('3.) Delete a book')
print('4.) search')
print('5.) Display all')
c = int(input("enter your choice\t"))
#adding a book
if(c==1):
b_id= int(input('Enter the book ID\t'))
b_name= input('Enter Name of the book\t')
author= input('Enter Author Name\t')
publication = input('Enter the name of the Publication\t')
isbn = int(input('Enter the ISBN code of book'))
price = int(input('Enter the price of book\t'))
qty = int(input('Enter the Quantity of books\t'))

cursor.execute("""INSERT INTO bookdetails


(b_id,b_name,author,publication,ISBN,price,quantity) VALUES
(?,?,?,?,?,?,?)""",(b_id,b_name,author,publication,isbn,price,qty))
sql_connect.commit()
#updating book
elif(c==2):
print('Update a book')
print('1.Update quantity')
print('2.Update ISBN')
print('3.Update Book name')
print('4.Update Price')
print('5.Update publication')
s = int(input("Enter your choice"))
#updating quantity of books available
if(s==1):
print('1. Add books')
print('2. Remove books')
sh=int(input('Enter choice'))
if(sh==1):
b_new_qty= int(input("Enter the number of books to be added"))
check_id= int(input('Enter the id of book whoose stock you want to add'))

j = cursor.execute("""SELECT quantity FROM bookdetails WHERE b_id =


? """,(check_id,)).fetchone()
no = j[0] + b_new_qty
print("Make sure you want to update\t",j[0],"\tfrom bookdetails table
to\t", no)
choice = int(input("Enter your choice\t 1.) for yes \t 2.) for no"))
if(choice==1):
cursor.execute("""UPDATE bookdetails SET quantity = ? WHERE b_id
=? """,(no,check_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print("Wrong choice")
elif(sh==2):
b_new_qty= int(input("Enter the number of books to be removed"))
check_id= int(input('Enter the id of book whoose stock you want to
remove'))

j = cursor.execute("""SELECT quantity FROM bookdetails WHERE b_id =


? """,(check_id,)).fetchone()
no = j[0] - b_new_qty
choice = int(input("Enter your choice\t 1.) for yes \t 2.) for no"))
if(choice==1):
cursor.execute("""UPDATE bookdetails SET quantity = ? WHERE b_id
=? """,(no,check_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print("Wrong choice")
return
#updating ISBN of a book
elif(s==2):
isbn_changed= int(input('Enter the new ISBN'))
check_id= int(input('Enter the id of book whoose ISBN you want to change'))

print("You really want to update book ID\t",check_id,"'s ISBN to",


isbn_changed)
choice=int(input("Enter your choice\n 1.) for yes \n 2.) for no"))
if(choice==1):
cursor.execute("""UPDATE bookdetails SET ISBN = ? WHERE b_id =?
""",(isbn_changed,check_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print("Wrong choice")
return
#updating Book NAME
elif(s==3):
name_changed= input('Enter the new Name')
check_id= int(input('Enter the id of book whoose name you want to
change'))
print("You really want to update book ID\t",check_id,"'s name to",
name_changed)
choice=int(input("Enter your choice\n 1.) for yes \n 2.) for no"))
if(choice==1):

cursor.execute("""UPDATE bookdetails SET b_name = ? WHERE b_id =?


""",(name_changed,check_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print("Wrong choice")
return
#updating book's price
elif(s==4):
new_price = int(input('Enter the new price'))
check_id= int(input('Enter the id of book whoose price you want to change'))

print("You really want to update book ID\t",check_id,"'s price to",


new_price)
choice=int(input("Enter your choice\n 1.) for yes \n 2.) for no"))
if(choice==1):
cursor.execute("""UPDATE bookdetails SET price = ? WHERE b_id =?
""",(new_price,check_id))
sql_connect.commit()
elif(choice==2):
return
else:
print("Wrong choice")
return
#updating publication name
elif(s==5):
new_publication = input('Enter the name of publication')

check_id= int(input('Enter the id of book whoose publication you want to


change'))
print("You really want to update book ID\t",check_id,"'s publication name
to", new_publication)
choice=int(input("Enter your choice\n 1.) for yes \n 2.) for no"))
if(choice==1):

cursor.execute("""UPDATE bookdetails SET publication = ? WHERE b_id


=? """,(new_publication,check_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print("Wrong choice")
return
else:
return
#Deleting a book from records
elif(c==3):
check_id= input('Enter the id of the book')
cursor.execute("""DELETE FROM bookdetails WHERE b_id = ? """, (check_id,))
sql_connect.commit()
#Search menu
elif(c==4):
print('Search Menu')
print('1. Search by book id')
print('2. Search by book name')
print('3. Search by ISBN')
print('4. Search by publisher')
char=int(input('Enter your choice\t'))
#search by book ID
if(char==1):
check_id= int(input('Enter the id of book'))
data= cursor.execute("""SELECT * FROM bookdetails WHERE b_id
=?""",(check_id,)).fetchone()
print("Book Name\t",data[1])
print("Book's Author\t",data[2])
print("Published by\t",data[3])
print('ISBN\t',data[4])
print('Price\t',data[5])
print('Quantity\t',data[6])
#search by Book NAME
elif(char==2):
b_check_name=input('Enter the name of book')

data= cursor.execute("""SELECT * FROM bookdetails WHERE b_name


=?""",(b_check_name,)).fetchone()
print("Book ID\t",data[0])
print("Book's Author\t",data[2])
print("Published by\t",data[3])
print('ISBN\t',data[4])
print('Price\t',data[5])
print('Quantity\t',data[6])
#search by ISBN
elif(char==3):
b_check_ISBN= int(input('Enter the ISBN of book'))
data= cursor.execute("""SELECT * FROM bookdetails WHERE ISBN
=?""",(b_check_ISBN)).fetchone()
print("Book ID\t",data[0])
print("Book Name\t",data[1])
print("Book's Author\t",data[2])
print("Published by\t",data[3])
print('Price\t',data[5])
print('Quantity\t',data[6])
#search by publisher
elif(char==4):
b_check_publisher= input('Enter the name of the publisher')

data= cursor.execute("""SELECT * FROM bookdetails WHERE publisher


=?""",(b_check_publisher)).fetchone()
print("Book ID\t",data[0])
print("Book Name\t",data[1])
print("Book's Author\t",data[2])
print('ISBN\t',data[4])
print('Price\t',data[5])
print('Quantity\t',data[6])
elif(char==5):
t=1
return
#display all book's data
elif(c==5):
results = cursor.execute(query).fetchall()
i=0
print("\tbook ID",end =" ")
print("\tBook name", end =" ")
print("\tBook's Author", end =" ")
print("\tBook's Publisher", end =" ")
print("%10s"%"%10s"%"\tBook's ISBN", end =" ")
print("\tPrice\t", end =" ")
print("\tQuantity Available")
print("="*140)
for row in results:
print("\t",row[0], end =" ")
print("\t",row[1], end =" ")
print("\t",row[2], end =" ")
print("\t",row[3], end =" ")
print("\t",row[4], end =" ")
print("\t\t",row[5], end =" ")
print("\t\t",row[6])
i=i+1
elif(c==6):
t=1
return
else:
print("Please enter correct")
#customer menu
def cMenu():
print('Customer Menu')
print('1.) Add Customer')
print('2.) Update a customer')
print('3.) Delete a customer')
print('4.) Search')
print('5) display All')
c= int(input("Enter your choice"))
#Creating a customer record
if(c==1):
c_id=int(input("Enter customer ID"))
c_name = input("Enter the Customer's name")
c_address = input("Enter the customer's Address")
c_phone = input("Enter the phone number")

cursor.execute("""INSERT INTO customerdetails


(c_id,c_name,c_address,c_phone) VALUES
(?,?,?,?))""",(c_id,c_name,c_address,c_phone,))
sql_connect.commit()
#Updating a customer's details
elif(c==2):
#update menu
print("Update Customer MENU")
print("1. Update Name")
print("2. Update Address")
print("3. Update phone number")
c= int(input("Enter your choice"))
#update Name
if(c==1):
c_id=int(input("Enter the customer ID"))
name= input("Enter the rectified name")
print("Are you sure you want to change name at ",c_id," to ",name)
print("Enter your choice")
choice= int(input("1.) Yes i want to change\n2.) No"))
if(choice==1):

cursor.execute("""UPDATE customerdetails SET c_name = ? WHERE c_id


=? """,(name,c_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print(" wrong choice ")
return
#Update Address
elif(c==2):
c_id=int(input("Enter the customer ID"))
address= input("Enter the rectified address")
print("Are you sure you want to change address at ",c_id," to ",address)
print("Enter your choice")
choice= int(input("1.) Yes i want to change\n2.) No"))
if(choice==1):

cursor.execute("""UPDATE customerdetails SET c_address = ? WHERE


c_id =? """,(address,c_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print(" wrong choice ")
return
#Update phone number
elif(c==3):
c_id=int(input("Enter the customer ID"))
phone= input("Enter the rectified phone number")
print("Are you sure you want to change phone no. at ",c_id," to ",phone)
print("Enter your choice")
choice= int(input("1.) Yes i want to change\n2.) No"))
if(choice==1):

cursor.execute("""UPDATE customerdetails SET c_address = ? WHERE


c_id =? """,(phone,c_id,))
sql_connect.commit()
elif(choice==2):
return
else:
print(" wrong choice ")
return
else:
return
#deleting a customer record
elif(c==3):
c_id= int(input("Enter customers ID"))
cursor.execute("""DELETE FROM customerdetails WHERE b_id =? """,(c_id,))
sql_connect.commit()
elif(c==4):
#search menu
print("Search menu")
print("1. Search by ID")
print("2. Search by Name")
rh=int(input('Enter your choice'))
#search by ID
if(rh==1):
c_id=int(input('Enter customer ID'))
results= cursor.execute("""SELECT * FROM customerdetails WHERE
c_id=?""",(c_id,)).fetchall
print("\tCustomer Name",end=" ")
print("\tCustomer Address",end=" ")
print("\tCustomer Phone no.")
print("="*140)
for row in results:
print("\t",row[1],end=" ")
print("\t",row[2],end=" ")
print("\t",row[3])
#search by Name
elif(rh==2):
c_name = input('Enter Customer Name')

results = cursor.execute("""SELECT * FROM customerdetails WHERE


c_name=?""",(c_name,)).fetchall()
print("\tCustomer I.D.",end=" ")
print("\tCustomer Name",end=" ")
print("\tCustomer Address",end=" ")
print("\tCustomer Phone no.")
print("="*140)
for row in results:
print("\t",row[0],end=" ")
print("\t",row[1],end=" ")
print("\t",row[2],end=" ")
print("\t",row[3])
elif(c==5):
#display all customer's details
results = cursor.execute(query2).fetchall()
j=0
print("\tCustomer I.D.",end=" ")
print("\tCustomer Name",end=" ")
print("\tCustomer Address",end=" ")
print("\tCustomer Phone no.")
print("="*140)
for row in results:
print("\t",row[0],end=" ")
print("\t",row[1],end=" ")
print("\t",row[2],end=" ")
print("\t",row[3])
else:
print("enter a correct choice")
#sales menu
def sMenu():
print('Sales Menu')
print('1.) Display All')
print('2.) Search')
print('3.) Add sales details')
print('4.) Sales table with customer details')
char = int(input("Enter your choice"))
#Display all customer's details
if(char==1):
results = cursor.execute(query3).fetchall()
j=0
for row in results:
print("Transaction ID",row[0])
print("Customer ID",row[1])
print("Book ID",row[2])
print("Date",row[3])
print("Total price",row[4])
j=j+1
#Search
elif(char==2):
#search menu
print('Search Menu')
print('1.) Search by transaction ID')
print('2.) Search by customer ID')
print('3.) Search by book ID')
print('4.) Search by date of sales')
print('5.) Show sales bookwise')
c=int(input("Enter your choice"))
#search by transaction ID
if(c==1):
t_id= int(input("Enter the Transaction ID"))

results = cursor.execute("""SELECT * FROM sales WHERE


t_id=?""",(t_id,)).fetchall()
j=0
for row in results:
print("Transaction ID",row[0])
print("CUSTOMER ID",row[1])
print("Book ID",row[2])
print("Date of sale",row[3])
print("quantity", row[4])
print("Total price", row[5])
j=j+1
#search by Customer ID
elif(c==2):
c_id= int(input("Enter the customer ID"))
results = cursor.execute("""SELECT * FROM sales WHERE
c_id=?""",(c_id,)).fetchall()
j=0
for row in results:
print("Transaction ID",row[0])
print("CUSTOMER ID",row[1])
print("Book ID",row[2])
print("Date of sale",row[3])
print("quantity", row[4])
print("Total price", row[5])
j=j+1
#search by Book ID
elif(c==3):
b_id= int(input("Enter the book ID"))

results = cursor.execute("""SELECT * FROM sales WHERE


b_id=?""",(b_id,)).fetchall()
j=0
for row in results:
print("Transaction ID",row[0])
print("CUSTOMER ID",row[1])
print("Book ID",row[2])
print("Date of sale",row[3])
print("quantity", row[4])
print("Total price", row[5])
j=j+1
#search by date of sales
elif(c==4):
date_of_sales=input("Enter the Date of Sales")
results = cursor.execute("""SELECT * FROM sales WHERE
date=?""",(date_of_sales,)).fetchall()
j=0
for row in results:
print("Transaction ID",row[0])
print("CUSTOMER ID",row[1])
print("Book ID",row[2])
print("Date of sale",row[3])
print("quantity", row[4])
print("Total price", row[5])
j=j+1
elif(c==5):
return
#Creating a sales record
elif(char==3):
t_id= int(input("ENTER TRANSACTION ID"))
c_id= int(input("ENTER CUSTOMER ID"))
b_id = int(input("ENTER BOOK DETAILS"))
date= input("ENTER DATE IN FORMAT YYYY-MM-DD")
quantity= int(input("ENTER THE QUANTITY OF BOOKS SOLD"))
total_price = int("ENTER TOTAL PRICE")

cursor.execute("""INSERT INTO SALES


(t_id,c_id,b_id,date,quantity,total_price)
VALUES(?,?,?,?,?,?)""",(t_id,c_id,b_id,date,quantity,total_price,))
sql_connect.commit()
#displaying sales records with customer names
elif(char==4):

joinquery = "SELECT sales.t_id sales.c_id customerdetails.c_name


customerdetails.c_phone sales.b_id FROM sales INNER JOIN customerdetails ON
sales.c_id=customerdetails.c_id"
result= cursor.execute(joinquery).fetchall()
j=0
print("TRANSACTION ID ",end=" ")
print("Customer ID ",end=" ")
print("Name of customer ",end=" ")
print("Phone no. ",end=" ")
print("Book ID ")
for row in result:
print("\t",row[0],end=" ")
print("\t",row[1],end=" ")
print("\t",row[2],end=" ")
print("\t",row[3],end=" ")
print("\t",row[4])
j=j+1
#displaying the sales records Book-wise
elif(char==5):

joinquery = "SELECT sales.t_id sales.b_id bookdetails.b_name


bookdetails.ISBN bookdetails.author bookdetails.publication sales.quantity FROM
sales INNER JOIN bookdetails ON sales.b_id=bookdetails.b_id"
result= cursor.execute(joinquery).fetchall()
j=0
for row in result:
print("TRANSACTION ID ",row[0])
print("Book ID ",row[1])
print("Name of book ",row[2])
print("Author ",row[4])
print("ISBN ",row[3])
print("publication",row[5])
print("Quantity ",row[6])
j=j+1
elif(char==6):
return
else:
print("ENTER A VALID OPTION")

while(t!=1):
#main menu
print("Main Menu")
print('1.) Book Details')
print('2.) Customer Details')
print('3.) Sales Menu')
print('4.) exit')
ch = int(input("Enter your choice\t"))
if(ch==1):
bookmenu()
elif(ch==2):
cMenu()
elif(ch==3):
sMenu()
elif(ch==4):
break
else:
print('please select a valid option')
OUTPUT SCREENS:
Development
Environment
Software:
1) Operating System (Windows 8 or later) : Windows 8 is selected as
my operating system because of additional file system, improved
performance on multi-core processors, improved boot performances,
security features and better GUI.

2) Database (Sqllite3): Sqllite3 is selected as database, main reason is


quite obvious it is prebuilt in the Python. It is free and open source
relational database management system.

3) Programming Language (Python): Python is also free and open


source programming language.

Hardware:
1) Processor: Intel i3 or AMD Ryzen processor

2) RAM : Minimum 2 GB required

3) Screen Resolution: Monitor with screen resolution minimum 1024x768


<

4) Hard Disk: Minimum 2GB is required for database.


BIBLIOGRAPHY
*Computer science with Python
- written by SumitaArora

*Computer science with Python


- written by Preeti Arora

*codereview.stackexchange.com

*fullstackpython.com
Thank You

You might also like