Acknowledgement: Mrs. BEENA PRASHANT For Her Constant Encouragement, Guidance
Acknowledgement: Mrs. BEENA PRASHANT For Her Constant Encouragement, Guidance
Acknowledgement: Mrs. BEENA PRASHANT For Her Constant Encouragement, Guidance
Nishchay Tandon
12th C (Commerce)
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.
Interesting fact: Python is named after title comedy television show
“Monty Python's Flying Circus”. It is not named after the Python snake.
Features of Python programming language
1
7. Supports exception handling: If you are new, you may wonder what is
an experience. An exception is an event that can occur during program
exception and can disrupt the normal flow of 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.
8. Advanced features: Supports generators and list comprehensions. We
will cover these features later.
2
Introduction to the
project
3
Index
Introduction to the
3
project
Code 4 - 32
Output 33 - 48
Bibliography 49
Thank you 50
Teachers Remarks 51
CODE
4
MEMBER
MODULE
import mysql.connector
from mysql.connector import errorcode
from datetime import date, datetime, timedelta
from mysql.connector import (connection)
5
import os
def clrscreen():
print('\n' *5)
def display():
try:
os.system('cls')
cnx = connection.MySQLConnection(user='root',
password='Nick2154',host='localhost',database='LIbrary')
Cursor = cnx.cursor()
query = ("SELECT * FROM Member")
Cursor.execute(query)
for (Mno,Mname,MOB,DOP,ADR) in Cursor:
print("=======================================================
=======")
print("Member Code : ",Mno)
print("Member Name : ",Mname)
print("Mobile No.of Member : ",MOB)
print("Date of Membership : ",DOP)
print("Address : ",ADR)
print("=======================================================
========")
Cursor.close()
cnx.close()
6
print("You have done it!!!!!!")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
cnx.close()
def insertMember():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1',database='Library')
Cursor = cnx.cursor()
mno=input("Enter Member Code : ")
mname=input("Enter Member Name : ")
mob=input("Enter Member Mobile No. : ")
print("Enter Date of Membership (Date/MOnth and Year seperately: ")
DD=int(input("Enter Date : "))
MM=int(input("Enter Month : "))
YY=int(input("Enter Year : "))
addr=input("Enter Member Adress : ")
Qry = ("INSERT INTO Member "\
7
"VALUES (%s, %s, %s, %s, %s)")
data = (mno,mname,mob,date(YY,MM,DD),addr)
Cursor.execute(Qry,data)
# Make sure data is committed to the database
cnx.commit()
Cursor.close()
cnx.close()
print("Record Inserted..............")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
def deleteMember():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1',database='Library')
Cursor = cnx.cursor()
mno=input("Enter Member Code to be deleted from the Library : ")
8
del_rec=(mno,)
Cursor.execute(Qry,del_rec)
cnx.close()
def SearchMember():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1',database='Library')
Cursor = cnx.cursor()
mnm=input("Enter Book Name to be Searched from the Library : ")
query = ("SELECT * FROM Member where MName = %s ")
9
rec_srch=(mnm,)
Cursor.execute(query,rec_srch)
Rec_count=0
for (Mno,Mname,MOB,DOP,ADR) in Cursor:
print("=======================================================
=======")
print("Member Code : ",Mno)
print("Member Name : ",Mname)
print("Mobile No.of Member : ",MOB)
print("Date of Membership : ",DOP)
print("Address : ",ADR)
print("=======================================================
========")
if Rec_count%2==0:
input("Press any key to continue")
clrscreen()
print(Rec_count, "Record(s) found")
# Make sure data is committed to the database
cnx.commit()
Cursor.close()
cnx.close()
10
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
11
issue MODULE
import mysql.connector
from mysql.connector import errorcode
from datetime import date
from mysql.connector import (connection)
import os
12
def clrscreen():
print('\n' *5)
def ShowIssuedBooks():
try:
os.system('cls')
cnx = connection.MySQLConnection(user='root',
password='Nick2154',host='localhost',database='Library')
Cursor = cnx.cursor()
query = ("SELECT B.bno,bname,M.mno,mname,d_o_issue,d_o_ret
FROM bookRecord B,issue I"\
",member M where B.bno=I.bno and I.mno=M.mno")
Cursor.execute(query)
for (Bno,Bname,Mno,Mname,doi,dor) in Cursor:
print("=======================================================
=======")
print("Book Code : ",Bno)
print("Book Name : ",Bname)
print("Member Code : ",Mno)
print("Member Name : ",Mname)
print("Date of issue : ",doi)
print("Date of return : ",dor)
print("=======================================================
========")
13
Cursor.close()
cnx.close()
print("You have done it!!!!!!")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
cnx.close()
def issueBook():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1',database='Library')
Cursor = cnx.cursor()
bno=input("Enter Book Code to issue : ")
mno=input("Enter Member Code : ")
print("Enter Date of Issue (Date/MOnth and Year seperately: ")
DD=int(input("Enter Date : "))
MM=int(input("Enter Month : "))
YY=int(input("Enter Year : "))
14
Qry = ("INSERT INTO issue (bno,mno,d_o_issue)"\
"VALUES (%s, %s, %s)")
data = (bno,mno,date(YY,MM,DD))
Cursor.execute(Qry,data)
cnx.commit()
Cursor.close()
cnx.close()
print("Record Inserted..............")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
def returnBook():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1',database='Library')
Cursor = cnx.cursor()
bno=input("Enter Book Code of Book to be returned to the Library : ")
Mno=input("Enter Member Code of Member who is returning Book : ")
retDate=date.today()
15
Qry =("""Update Issue set d_o_ret= %s WHERE BNO = %s and Mno= %s
""")
rec=(retDate,bno,Mno)
Cursor.execute(Qry,rec)
16
Book MODULE
import mysql.connector
from mysql.connector import errorcode
from datetime import date, datetime, timedelta
from mysql.connector import (connection)
import os
import platform
def clrscreen():
if platform.system()=="Windows":
17
print(os.system("cls"))
def display():
try:
os.system('cls')
cnx = connection.MySQLConnection(user='root',
password='Nick2154',host='localhost', database='LIbrary')
Cursor = cnx.cursor()
query = ("SELECT * FROM BookRecord")
Cursor.execute(query)
for (Bno,Bname,Author,price,publ,qty,d_o_purchase) in Cursor:
print("=======================================================
=======")
print("Book Code : ",Bno)
print("Book Name : ",Bname)
print("Author of Book : ",Author)
print("Price of Book : ",price)
print("Publisher : ",publ)
print("Total Quantity in Hand : ",qty)
print("Purchased On : ",d_o_purchase)
print("=======================================================
========")
Cursor.close()
cnx.close()
print("You have done it!!!!!!")
except mysql.connector.Error as err:
18
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
cnx.close()
def insertData():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1',database='Library')
Cursor = cnx.cursor()
bno=input("Enter Book Code : ")
bname=input("Enter Book Name : ")
Auth=input("Enter Book Author's Name : ")
price=int(input("Enter Book Price : "))
publ=input("Enter Publisher of Book : ")
qty=int(input("Enter Quantity purchased : "))
print("Enter Date of Purchase (Date/MOnth and Year seperately: ")
DD=int(input("Enter Date : "))
MM=int(input("Enter Month : "))
YY=int(input("Enter Year : "))
Qry = ("INSERT INTO BookRecord "\
19
"VALUES (%s, %s, %s, %s, %s, %s, %s)")
data = (bno,bname,Auth,price,publ,qty,date(YY,MM,DD))
Cursor.execute(Qry,data)
# Make sure data is committed to the database
cnx.commit()
Cursor.close()
cnx.close()
print("Record Inserted..............")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
def deleteBook():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1',database='Library')
Cursor = cnx.cursor()
bno=input("Enter Book Code of Book to be deleted from the Library : ")
20
del_rec=(bno,)
Cursor.execute(Qry,del_rec)
cnx.close()
def SearchBookRec():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1', database='Library')
Cursor = cnx.cursor()
bno=input("Enter Book No to be Searched from the Library : ")
query = ("SELECT * FROM BookRecord where BNo = %s ")
21
rec_srch=(bno,)
Cursor.execute(query,rec_srch)
Rec_count=0
print("=======================================================
=======")
print("Book Code : ",Bno)
print("Book Name : ",Bname)
print("Author of Book : ",Author)
print("Price of Book : ",price)
print("Publisher : ",publ)
print("Total Quantity in Hand : ",qty)
print("Purchased On : ",d_o_purchase)
print("=======================================================
========")
if Rec_count%2==0:
input("Press any key to continue")
clrscreen()
print(Rec_count, "Record(s) found")
# Make sure data is committed to the database
cnx.commit()
22
Cursor.close()
cnx.close()
cnx.close()
def UpdateBook():
try:
cnx =
connection.MySQLConnection(user='root',password='Nick2154',host='12
7.0.0.1', database='Library')
Cursor = cnx.cursor()
bno=input("Enter Book Code of Book to be Updated from the Library :
")
query = ("SELECT * FROM BookRecord where BNo = %s ")
rec_srch=(bno,)
print("Enter new data ")
bname=input("Enter Book Name : ")
Auth=input("Enter Book Author's Name : ")
price=int(input("Enter Book Price : "))
23
publ=input("Enter Publisher of Book : ")
qty=int(input("Enter Quantity purchased : "))
print("Enter Date of Purchase (Date/MOnth and Year seperately: ")
DD=int(input("Enter Date : "))
MM=int(input("Enter Month : "))
YY=int(input("Enter Year : "))
Qry = ("UPDATE BookRecord SET bname=%s,Author=%s,"\
"price=%s,publ=%s,qty=%s,d_o_purchase=%s "\"WHERE BNO=%s")
data = (bname,Auth,price,publ,qty,date(YY,MM,DD),bno)
Cursor.execute(Qry,data)
# Make sure data is committed to database
cnx.commit()
Cursor.close()
cnx.close()
print(Cursor.rowcount,"Record(s) Updated Successfully.............")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
UpdateBook()
24
MENULIB
MODULE
25
import Book
import Member
import Issue
def MenuBook():
while True:
Book.clrscreen()
print("\t\t\t Book Record Management\n")
print("=======================================================
=======")
print("1. Add Book Record ")
print("2. Display Book Records ")
print("3. Search Book Record ")
print("4. Delete Book Record ")
26
print("5. Update Book Record ")
print("6. Return to Main Menu ")
print("=======================================================
========")
choice=int(input("Enter Choice between 1 to 5-------> : "))
if choice==1:
Book.insertData()
elif choice==2:
Book.display()
elif choice==3:
Book.SearchBookRec()
elif choice==4:
Book.deleteBook()
elif choice==5:
print("No such Function")
elif choice==6:
return
else:
print("Wrong Choice......Enter Your Choice again")
x=input("Enter any key to continue")
#----------------------------------------------------------------------------------------
def MenuMember():
while True:
Book.clrscreen()
print("\t\t\t Member Record Management\n")
27
print("=======================================================
=======")
print("1. Add Member Record ")
print("2. Display Member Records ")
print("3. Search Member Record ")
print("4. Delete Member Record ")
print("5. Update Book Record ")
print("6. Return to Main Menu ")
print("=======================================================
========")
choice=int(input("Enter Choice between 1 to 5-------> : "))
if choice==1:
Member.insertData()
elif choice==2:
Member.display()
elif choice==3:
Member.SearchMember()
elif choice==4:
Member.deleteMember()
elif choice==5:
print("No such Function")
elif choice==6:
return
else:
28
print("Wrong Choice......Enter Your Choice again")
x=input("Enter any key to continue")
#----------------------------------------------------------------------------------------
def MenuIssueReturn():
while True:
Book.clrscreen()
print("\t\t\t Member Record Management\n")
print("=======================================================
=======")
print("1. Issue Book ")
print("2. Display Issued Book Records ")
print("3. Return Issued Book ")
print("4. Return to Main Menu ")
print("=======================================================
========")
choice=int(input("Enter Choice between 1 to 5-------> : "))
if choice==1:
Issue.issueBookData()
elif choice==2:
Issue.ShowIssuedBooks()
elif choice==3:
Issue.returnBook()
elif choice==4:
return
29
else:
print("Wrong Choice......Enter Your Choice again")
x=input("Enter any key to continue")
LIBRARY
MANAGEMENT
30
import MenuLib
import Book
import Issue
while True:
Book.clrscreen()
print("\t\t\t Library Management\n")
print("=======================================================
=======")
print("1. Book Management ")
print("2. Members Management s ")
print("3. Issue/Return Book ")
print("4. Exit ")
print("=======================================================
========")
choice=int(input("Enter Choice between 1 to 4-------> : "))
if choice==1:
31
MenuLib.MenuBook()
elif choice==2:
MenuLib.MenuMember()
elif choice==3:
MenuLib.MenuIssueReturn()
elif choice==4:
break
else:
print("Wrong Choice......Enter Your Choice again")
x=input("Enter any key to continue")
32
Output
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Bibliography
This are the following sites which helped me to get the information for
this project apart from Sumita Arora textbook of informatics practices.
www.pythonworld.in
www.w3schools.com
www.pathwala.comm
But also informatics practices of Sumita Arora were very helpful for the
completion of this project.
49
Thank
You
Teachers Remarks :-
50