diff --git a/Library management system /__pycache__/Bill.cpython-39.pyc b/Library management system /__pycache__/Bill.cpython-39.pyc new file mode 100644 index 0000000..2455863 Binary files /dev/null and b/Library management system /__pycache__/Bill.cpython-39.pyc differ diff --git a/Library management system /__pycache__/Book.cpython-39.pyc b/Library management system /__pycache__/Book.cpython-39.pyc new file mode 100644 index 0000000..e433043 Binary files /dev/null and b/Library management system /__pycache__/Book.cpython-39.pyc differ diff --git a/Library management system /__pycache__/Return.cpython-39.pyc b/Library management system /__pycache__/Return.cpython-39.pyc new file mode 100644 index 0000000..31ce873 Binary files /dev/null and b/Library management system /__pycache__/Return.cpython-39.pyc differ diff --git a/Library management system /__pycache__/borrow.cpython-39.pyc b/Library management system /__pycache__/borrow.cpython-39.pyc new file mode 100644 index 0000000..d1cd754 Binary files /dev/null and b/Library management system /__pycache__/borrow.cpython-39.pyc differ diff --git a/Library management system /__pycache__/main.cpython-39.pyc b/Library management system /__pycache__/main.cpython-39.pyc new file mode 100644 index 0000000..4c6b991 Binary files /dev/null and b/Library management system /__pycache__/main.cpython-39.pyc differ diff --git a/Library management system/Bill.py b/Library management system/Bill.py new file mode 100644 index 0000000..4bd6728 --- /dev/null +++ b/Library management system/Bill.py @@ -0,0 +1,36 @@ +import borrow + +# creating Bill function +def Bill(f_name,sum,today,current_time): + print(borrow.borrowedBooks) + sum = "{:.2f}".format(sum) + print("\n"+"++" * 30) + print("Customer Bill!!!".center(50)+ "\n" + "++" * 30 + "\n") + print("Name of Customer: ",f_name) + print("Sum is $",sum) + print("Date and Time of Borrow is: ",today,current_time) + print("Name of Books Borrowed: ") + + for i in(borrow.borrowedBooks): + print(i) + x=current_time.replace(":","") + fileName = "Borrow_"+ f_name + str(today)+ x+ ".txt" + print("++" *30 +"\n\n\n") + + file= open(fileName,'w') + file.write("Borrow Details:"+ "\n") + file.write("Name of Person: "+ f_name +"\n") + file.write("Total Price of Books: "+str(sum) +"\n") + file.write("Date and time of Borrow is: "+str(today) ) + file.write( str(current_time) +"\n") + file.write("Books Borrowed are: "+"\n") + + for books in (borrow.borrowedBooks): + file.write(books + "\n") + + + file.close() + borrow.borrowedBooks.clear() + borrow.borrowedID.clear() + + diff --git a/Library management system/Book.py b/Library management system/Book.py new file mode 100644 index 0000000..7f76b86 --- /dev/null +++ b/Library management system/Book.py @@ -0,0 +1,54 @@ +import borrow + +#Creating Book function +def Book(): + print("---" * 35) + print("Book ID".ljust(17), "Book-Name".ljust(30) + "Author".ljust(20) + "Quantity".ljust(17) + "Price".ljust(15)) + print("---" * 35) + + #Opening and reading txt file + file = open('books.txt', 'r') + content = file.readlines() + def splitLines(): + for each in content: + splitList = each.split(',') + bookID = splitList[0] + title = splitList[1].ljust(25) + if len(title) > 25: + title = title[0:22].ljust(25, '.') + author = splitList[2].ljust(25) + quantity = splitList[3].ljust(15) + price = splitList[4].ljust(15) + + print(bookID.ljust(15) + title + " " * 5 + author + quantity + price) + borrow.bookDictionary[int(splitList[0])] = [splitList[1].strip(), splitList[2].strip(), int(splitList[3].strip()), splitList[4].strip()] + print("\n",borrow.bookDictionary) + print("\n") + splitLines() + file.close() + +#Creating moreBooks functon +def moreBooks(): + + bookIDList = [] + for each in borrow.bookDictionary: + bookIDList.append(each) + bookID = int(input("Enter another borrowed book: ")) + + if bookID not in bookIDList: + print("\n" + "++" * 30 + "\n") + print("Please provide a valid Book ID !!!".center(50) + "\n" + "++" * 30 + "\n") + moreBooks(sum) + + borrow.borrowedID.append(bookID) + borrow.borrowedBooks.append(borrow.bookDictionary[bookID][0]) + price2 = borrow.bookDictionary[bookID][3] + print("The price of book is: ",price2 + "\n") + print("Has This Person Borrowed Another Book?") + AnotherBook = input("If yes then type Y ,if not they type n: " ) + if AnotherBook.lower() == "y": + moreBooks() + else: + return + + diff --git a/Library management system/Return.py b/Library management system/Return.py new file mode 100644 index 0000000..7acf455 --- /dev/null +++ b/Library management system/Return.py @@ -0,0 +1,69 @@ +from datetime import date +from datetime import datetime +import borrow +# Creating return_books function +def return_books(): + total = 0 + bookIDList = [] + + today = date.today() + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + + #Asking user details + for each in borrow.bookDictionary: + bookIDList.append(each) + f_name = input("Name of person who returned Book: ") + bookID = int(input("Enter book id to return book: ")) + + #Checking user input + if bookID not in bookIDList: + print("\n" + "++" * 30 + "\n") + print("Please provide a valid Book ID !!!".center(50) + "\n" + "++" * 30 + "\n") + return_books() + if bookID in bookIDList: + quantity = borrow.bookDictionary[bookID][2] + price = borrow.bookDictionary[bookID][3] + book_name = borrow.bookDictionary[bookID][0] + author_name = borrow.bookDictionary[bookID][1] + + quantity =int(quantity)+1 + total+=float(price[1:]) + print(str(total)) + # checking for fine + print("Is the book return date expired?") + Expire = input("Press Y for Yes and N for No: ") + x=current_time.replace(":","") + if(Expire.upper()=="Y"): + day = int(input("By how many days was the book returned late?")) + fine=3*day + total=total+fine + else: + fine = 0 + total = "{:.2f}".format(total) + + fileName="Return-"+f_name+str(today)+ x+".txt" + file = open(fileName,'w') + file.write("Return Details: \n") + file.write("Name of Person: "+ f_name+"\n") + file.write("Date and time of return is: "+str(today)+ " " ) + file.write(str(current_time) +"\n") + file.write("Books Returend are: "+ borrow.bookDictionary[bookID][0]+"\n") + file.write("Price is: " +borrow.bookDictionary[bookID][3]+ "\n") + file.write("Fine is: "+ str(fine)+"\n") + print("Total Bill: "+ "$"+str(total)) + file.write("Total: $"+ str(total)) + + # Writing in file + borrow.bookDictionary[bookID][2]+= 1 + with open('books.txt', 'w') as f: + for i in range(1, 6): + f.write(str(i)) + f.write(",") + for j in range(4): + if(j == 3): + f.write(str(borrow.bookDictionary[i][j])) + else: + f.write(str(borrow.bookDictionary[i][j])) + f.write(", ") + f.write("\n") diff --git a/Library management system/books.txt b/Library management system/books.txt new file mode 100644 index 0000000..329ff36 --- /dev/null +++ b/Library management system/books.txt @@ -0,0 +1,5 @@ +1,The Alchemist, Paulo Coelho, 82, $4.99, +2,Harry Potter, J.K Rowling, 8, $9.99, +3,vampire Diaries, L.J Smith, 1, $12.00, +4,Don Quixote, Miguel de Cervantes, 96, $15.00, +5,Beloved, Toni Morrison, 93, $20, diff --git a/Library management system/borrow.py b/Library management system/borrow.py new file mode 100644 index 0000000..fc4e570 --- /dev/null +++ b/Library management system/borrow.py @@ -0,0 +1,84 @@ +from datetime import date +from datetime import datetime +import Book +import Bill + + +#definingempty dictionary and list +bookDictionary = {} +borrowedBooks = [] +borrowedID = [] + +#Creating borrowBook Function +def borrowBook(): + sum = 0 + bookIDList = [] + #checking user input + for each in bookDictionary: + bookIDList.append(each) + bookID = int(input("Enter book id to borrow book: ")) + + if bookID not in bookIDList: + print("\n" + "++" * 30 + "\n") + print("Please provide a valid Book ID !!!".center(50) + "\n" + "++" * 30 + "\n") + borrowBook() + + if bookID in bookIDList: + + borrowedBooks.append(bookDictionary[bookID][0]) + borrowedID.append(bookID) + quantity = bookDictionary[bookID][2] + if quantity == 0: + print("\n" + "++" * 30 + "\n" + "Book is not available!!!".center(50) + "\n" + "++" * 30 + "\n") + from main import main + + else: + print("\n" + "++" * 30 + "\n" + "Book is available!!!".center(50) + "\n" + "++" * 30 + "\n") + + f_name = input("Enter the Name of person who borrowed book: ") + price = bookDictionary[bookID][3] + print("The price of book is: ",price) + + #adding date and time + today = date.today() + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + + print("Today's date and Time: ", today,current_time, "\n") + + #writing in file + bookDictionary[bookID][2]-= 1 + + with open('books.txt', 'w') as f: + for i in range(1, 6): + f.write(str(i)) + f.write(",") + for j in range(4): + if(j == 3): + + f.write(str(bookDictionary[i][j])) + else: + f.write(str(bookDictionary[i][j])) + f.write(", ") + f.write("\n") + + + print("List after a Borrow: ") + Book.Book() + print("Has This Person Borrowed Another Book?") + AnotherBook = input("If yes then type Y ,if not they type n: ") + if AnotherBook.lower() == "y": + Book.moreBooks() + + + for x in(borrowedID): + p = bookDictionary[x][3] + price = p[1:] + sum = sum + float(price) + #printing bill + Bill.Bill(f_name,sum,today,current_time) + + + + + diff --git a/Library management system/main.py b/Library management system/main.py new file mode 100644 index 0000000..b129aa5 --- /dev/null +++ b/Library management system/main.py @@ -0,0 +1,44 @@ +import borrow +import Book +import Return +import Bill + +#Defining main function +def main(): + # using while loop + while(True): + print("+++" * 35) + print("Hello and Welcome to library management system".center(100)) + print("+++" * 35+ "\n\n") + Book.Book() + print("Enter 1 to Borrow a Book") + print("Enter 2 to Return a book") + print("Enter 3 to Exit") + + #Using try and catch for exception Handling + try: + userInput = int(input("Please enter a value: ")) + print() + # Taking input from user + if(userInput==1): + print("You will now borrow a book") + borrow.borrowBook() + main() + break + elif(userInput==2): + print("You will now reuturn a Book") + Return.return_books() + + elif(userInput==3): + print("---"* 30) + print("\n Thank you for using Library management system\n".center(100)) + print("---"* 30) + break + except ValueError: + print("++" *30) + print("Invalid Input!!\n Please enter 1, 2 or 3") + print("++" *30+ "\n\n") + +# calling main function +main() +