Computer Science Project - 12
Computer Science Project - 12
COMPUTER SCIENCE
PROJECT 2022-2023
NAME :
REG.NO.:
SUBJECT : PYTHON
ACKNOWLEDGEMENT
In the accomplishment of this project
successfully So many people have bestowed
upon me their blessings and the heart
pledged support, this time I am utilizing to
thank all people who have been concerned
with the project.
ACHNOWLEDGEMENT
INTRODUCTION
MODULES AND FUNCTIONS
USED
HARDWARE & SOFTWARE
REQUIREMENTS
SOURCE CODE
OUTPUT
BIBLIOGRAPHY
INTRODUCTION
LIBRARY MANAGEMENT:
A library management system is
software that is designed to manage all the
functions of a library. It helps librarian to
maintain the database of new books and the
books that are borrowed by members along
with their due dates.
This system completely automates all your
library's activities. The best way to maintain,
organize, and handle countless books
systematically is to implement a library
management system software.
You can find books in an instant, Issue/reissue
books quickly, and manage all the data efficiently
and orderly using this system. The purpose of a
library management system is to provide instant
and accurate data regarding any type of book,
thereby saving a lot of time and effort.
MODULE AND FUNCTIONS
USED
Tabulate Function
Visualizing the data in tabular form is
easier than visualizing it in a paragraph
or comma-separated form. Nicely
formatted tables not only provide you
with a better way of looking at tables it
can also help in understanding each data
point clearly with its heading and value
.
Tabulate is an open-source python
package/module which is used to print
tabular data in nicely formatted tables.
It is easy to use and contains a variety of
formatting functions.
It has the following functionalities:
One function call for all types
of formatting
Can be downloaded in multiple
output formats
Provides a better presentation
with text and data.
HARDWARE REUIREMENTS :-
SOFTWARE REQUIREMENTS:-
WINDOWS 7,10 OR 11
MAC OS X 10.11 OR HIGHER , 64 BIT
LINUX: RHEL 6/7, 64-BIT (ALMOST ALL LIBRARY
WORK)
SOURCE CODE
#CREATING DATABASE
import mysql.connector
mydb=mysql.connector.connect(host="localhost",
user="root",passwd="1234") mycursor=mydb.cursor()
mycursor.execute("create database if not exists library")
mycursor.execute("use library")
#CREATING REQUIRED TABLES
#PRINT MENU
while True:
print("")
print("-"*100)
print("MAIN MENU".center(90))
print("-"*100) print("1 Create a new
account") print("2 See the account
info") print("3 Update card holder
info") print("4 Delete the account")
print("5 Add new book") print("6 See
books") print("7 Update book details")
print("8 Delete book") print("9 lend a
book") print("10 return the book")
print("11 display lending history")
print("12 EXIT")
print(" ")
ch=int(input("enter your choice:- "))
print(" ")
#TO CREATE A LIBRARY ACCOUNT
if ch==1:
try: cardno=str(input("enter card no: ")) name_of_person=str(input("Enter
name (limit 30 characters): ")) phone_no=str(input("Enter phone no: "))
address=str(input("Enter the address (max 30 words): "))
dob=str(input("Enter the date of birth(yyyy-mm-dd): "))
mycursor.execute("insert into library_master
values('"+cardno+"','"+name_of_person+"','"+phone_no+"',
'"+address+"','"+do b+"')")
mydb.commit() print("ACCOUNT IS SUCCESSFULLY
CREATED!!!")
if ch==2:
try: cardno=str(input("Enter card no:- ")) mycursor.execute("select
* from library_master where cardno='"+cardno+"'")
print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql'))
except Exception as e: print("Something
went wrong ",e)
#TO UPDATE CARD HOLDER INFORMATION
if ch==3:
try: print("") print("press 1 to update name:")
print("press 2 to update phone no:") print("press 3
to update address:") print("press 4 to update date
of birth:") print("press 5 to update ALL the
details:") ch1=int(input("Enter your choice:- "))
if ch1==1:
try: mycursor.execute("select * from library_master") print("Current
record") print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql'))
cardno=str(input("Enter card no:-"))
name_of_person=str(input("Enter new name:-"))
mycursor.execute("update library_master set
name_of_person='"+name_of_person+"' where
cardno='"+cardno+"'")
mydb.commit() print("Name has been updated")
mycursor.execute("select * from library_master")
print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql')) except
Exception as e: print("Something went
wrong ",e)
#TO UPDATE PHONE NUMBER
if ch1==2:
try: mycursor.execute("select * from library_master") print("Current
record") print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql')) cardno=str(input("Enter
card no:-")) phone_no=str(input("Enter new phone no:-"))
mycursor.execute("update library_master set
phone_no='"+phone_no+"' where cardno='"+cardno+"'")
No','Address','DOB'],tablefmt='psql'))
except Exception as e: print("Something
went wrong ",e)
#TO UPDATE ADDRESS
No','Address','DOB'],tablefmt='psql'))
cardno=str(input("Enter card no:- "))
address=str(input("Enter new address:- "))
mycursor.execute("update library_master set address='"+address+"'
where cardno='"+cardno+"'")
mydb.commit() print("Address has been updated")
mycursor.execute("select * from library_master")
print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql'))
except Exception as e: print("Something
went wrong ",e)
if ch1==4:
try: mycursor.execute("select * from library_master") print("Current
record") print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql'))
cardno=str(input("Enter card no:- "))
dob=str(input("Enter new date of birth(yyyy-mm-dd):"))
mycursor.execute("update library_master set dob='"+dob+"' where
cardno='"+cardno+"'")
mydb.commit() print("Date of birth has been updated")
mycursor.execute("select * from library_master")
print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql')) except Exception as e:
print("Something went wrong ",e)
#TO UPDATE ALL DETAILS
if ch1==5:
try: mycursor.execute("select * from library_master")
print("Current record")
print(tabulate(mycursor,headers=['Card
No.','Name','Phone No','Address','DOB'],tablefmt='psql'))
if ch==4:
try: mycursor.execute("select * from library_master") print("Accounts
Available") print(tabulate(mycursor,headers=['Card
No.','Name','Phone
No','Address','DOB'],tablefmt='psql'))
cardno=str(input("Enter card no:"))
mycursor.execute("delete from library_master where
cardno='"+cardno+"'")
mydb.commit() print("Removed succesfully")
mycursor.execute("select * from library_master")
print(tabulate(mycursor,headers=['Card No.','Name','Phone
No','Address','DOB'],tablefmt='psql')) except
Exception as e: print("Something went
wrong ",e)
if ch==5:
try: print("") print("FILL ALL BOOK DETAILS ") book_name=str(input("enter book
name:- ")) book_no=str(input("Enter no (limit 5 characters):- ")) genre=str(input("Enter
genre:- ")) authors_name=str(input("Enter the authors name (max 15 words):- "))
language=str(input("Enter the language of book:")) mycursor.execute("insert into books
values('"+book_name+"','"+book_no+"','"+genre+"','"+authors_name+"','"+language+"')")
print("Book added succesfully") mydb.commit() except Exception as e: print("Something
went wrong ",e)
#TO SEE BOOK DETAILS
if ch==6:
try:
book_no=str(input("Enter Book No:")) mycursor.execute("select *
from books where book_no='"+book_no+"'")
print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours
Name','Language'],tablefmt='psql'))
except Exception as e: print("Something
went wrong ",e)
#TO UPDATE BOOK DETAILS
if ch==7:
print("") print("press 1 to update Book
name") print("press 2 to update genre")
print("press 3 to update Author Name")
print("press 4 to update Language")
ch1=int(input("Enter your choice:"))
if ch1==1:
try: print("Current Books") mycursor.execute("select * from
books") print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours Name',
'Language'],tablefmt='psql'))
book_no=str(input("Enter bookno:- "))
name_of_book=str(input("Enter new name:- "))
mycursor.execute("update books set
book_name='"+name_of_book+"' where book_no='"+book_no+"'")
mydb.commit()
print("Name has been updated")
mycursor.execute("select * from books")
print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours
Name','Language'],tablefmt='psql')) except
Exception as e: print("Something went
wrong ",e)
#TO UPDATE GENRE
if ch1==2:
try: print("Current Record") mycursor.execute("select * from books")
book_no=str(input("Enter card no:")) genre=str(input("Enter new
genre:")) mycursor.execute("update books set genre='"+genre+"' where
book_no='"+book_no+"'") mydb.commit() print("*Genre has been
updated*") mycursor.execute("select * from books")
print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours Name','Language'],tablefmt='psql'))
if ch1==3:
try: print("Current Record") mycursor.execute("select * from books")
book_no=str(input("Enter book no:")) author=str(input("Enter new
authors name:")) mycursor.execute("update books set
authors_name='"+author+"' where book_no='"+book_no+"'")
mydb.commit() print("*Authors name has been updated*")
mycursor.execute("select * from books")
print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours Name','Language'],tablefmt='psql'))
if ch1==4:
try: print("Current Record") mycursor.execute("select * from books")
book_no=str(input("Enter boom no:")) language=str(input("Enter new
language:")) mycursor.execute("update books set language='"+language+"'
where book_no='"+book_no+"'") mydb.commit() print("*Language has been
updated*") mycursor.execute("select * from books")
print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours Name','Language'],tablefmt='psql'))
if ch1==5:
try: print("Current Record") mycursor.execute("select * from
books") print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours
Name','Language'],tablefmt='psql')) book_no=str(input("Enter bookno:"))
name_of_book=str(input("Enter new name:")) mycursor.execute("update
books set book_name='"+name_of_book+"' where book_no='"+book_no+"'")
book_no='"+book_no+"'") mydb.commit()
mycursor.execute("select * from books")
print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours Name','Language'],tablefmt='psql'))
if ch==8:
try: print("Current Record") mycursor.execute("select *
from books") print(tabulate(mycursor,headers=['Book
Name','book
Number','Genre','Authours Name','Language'],tablefmt='psql'))
book_no=str(input("Enter book no:")) mycursor.execute("delete from books
where book_no='"+book_no+"'") mydb.commit() print("*Removed
succesfully*") mycursor.execute("select * from books")
print(tabulate(mycursor,headers=['Book Name','book
Number','Genre','Authours Name','Language'],tablefmt='psql'))
if ch==9:
try: cardno=str(input("Enter card no:")) book_name=str(input("Enter the name of the
book:")) date_of_lend=str(input("Enter date of lending(yyyy-mm-dd)")) print("if book
not returned then enter(0000-00-00):") date_of_return=str(input("enter date of
return(yyyy-mm-dd):")) mycursor.execute("insert into library_transaction
values('"+cardno+"','"+book_name+"','"+date_of_lend+"','"+date_of_return+"')") except
Exception as e: print("Something went wrong ",e)
#TO RETURN A BOOK
if ch==10:
try: cardno=str(input("Enter card no:")) date_of_return=str(input("Enter date
of returning(yyyy-mm-dd):")) mycursor.execute("update library_transaction
set date_of_return='"+date_of_return+"' where cardno='"+cardno+"'")
mydb.commit() except Exception as e: print("Something went wrong ",e)
if ch==11:
cardno=str(input("Enter card no:"))
mycursor.execute("select * from library_transaction where
cardno='"+cardno+"'") print(tabulate(mycursor,headers=['Card Number','book
Number','Date of lend','Date of return'],tablefmt='psql'))
if ch==12:
print("Thank you :)")
break
else:
print("Enter correct input!!!")
OUTPUT
----------------------------------------------------------------------------------------------------
MAIN MENU
----------------------------------------------------------------------------------------------------
1 Create a new account
2 See the account info
3 Update card holder info
4 Delete the account
5 Add new book
6 See books
7 Update book details
8 Delete book
9 lend a book
10 return the book
11 display lending history
12 EXIT
Accounts Available
+------------+--------+------------+------------+------------+
| Card No. | Name | Phone No | Address | DOB |
|------------+--------+------------+------------+------------| 1
| | Hussain | 9812345678 | ABC colony | 2005-08-10 |
| 2 | Hatim | 9845672592 | ABC Colony | 2005-11-23 |
+------------+--------+------------+------------+------------+
Enter card no:1
Removed successfully
Remaining Records:-
+------------+--------+------------+------------+------------+
| Card No. | Name | Phone No | Address | DOB |
|------------+--------+------------+------------+------------|
| 2 +------------+--------+------------+------------+------------+
Abi| | 9845672592 | ABC Colony | 2005-11-23 |
www.python.org
www.w3schools.com
www.pythonlobby.com
www.skoolbeep.com
www.programiz.com