0% found this document useful (0 votes)
32 views2 pages

Library Final Skeleton

The document contains code for a library management system that allows users to issue books, return books, view not returned books, add new books and students, and search for books and students. The code defines functions for each operation and a main loop that calls the functions based on user input.

Uploaded by

shubhamcollege11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Library Final Skeleton

The document contains code for a library management system that allows users to issue books, return books, view not returned books, add new books and students, and search for books and students. The code defines functions for each operation and a main loop that calls the functions based on user input.

Uploaded by

shubhamcollege11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import datetime

def issue_book():
bnum = input("Enter Book Number : ")
enr = input("Enter Student Enrollment Number : ")
a = datetime.date.today()
idate = str(a.day) + "-" + str(a.month) + "-" + str(a.year)

fobj = open("all_issued.txt", "a")


fobj.write(bnum + "," + enr + "," + idate + "," + "NR\n")
fobj.close()
print("Book Issued...")

def return_book():
bnum = input("Enter Book Number to Return :")
a = datetime.date.today()
rdate = str(a.day) + "-" + str(a.month) + "-" + str(a.year)

flag = 1
fobj = open("all_issued.txt", "r")
all_lines = fobj.readlines()
i = 0
while i<len(all_lines):
oneline = all_lines[i]
ls = oneline.split(",")
if ls[0]==bnum and ls[3]=="NR\n":
ls[3] = rdate + "\n"
new_str = ",".join(ls)
all_lines[i] = new_str
flag = 2
break
i = i + 1
if flag==1:
print("Invalid Book Number. No such Book is Issued..")
fobj.close()

if flag==2:
fobj2 = open("all_issued.txt", "w")
fobj2.writelines(all_lines)
fobj2.close()
print("Book Returned..")

def view_not_ret_books():
fobj = open("all_issued.txt", "r")
for oneline in fobj:
ls = oneline.split(",")
if ls[3]=="NR\n":
print(ls[0], ls[1], ls[2], sep="\t")
fobj.close()

def add_new_book():
# bnum = input("Enter Book Number : ")
fobj = open("all_books.txt", "r")
all_lines_ls = fobj.readlines()
fobj.close()

bnum = len(all_lines_ls) + 1
btitle = input("Enter Book Title : ")
bauth = input("Enter Book Author : ")
bpublication = input("Enter Publication Name : ")

fobj = open("all_books.txt", "a")


fobj.write(str(bnum) + "," + btitle + "," + bauth + "," + bpublication + "\n")
fobj.close()
print("New Book Added...")

def add_new_stud():
pass

def book_history():
pass

def stud_history():
pass

def search_book():
pass

def search_stud():
pass

while True:
input()
print("Select operation")
print("1 - Issue Book")
print("2 - Return Book")
print("3 - View Not Returned Books")
print("4 - Add New Book")
print("5 - Add New Student")
print("6 - Search Book")
print("7 - Search Student")
print("8 - Book History")
print("9 - Student History")
print("0 - EXIT")
ch = int(input("Provide your choice : ") )
if ch==1: issue_book()
elif ch==2: return_book()
elif ch==3: view_not_ret_books()
elif ch==4: add_new_book()
elif ch==5: add_new_stud()
elif ch==6: search_book()
elif ch==7: search_stud()
elif ch==8: book_history()
elif ch==9: stud_history()
elif ch==0: exit(0)

You might also like