├── FLow lms_1.jpg ├── Flow Chart LMS_1.jpg ├── Flow Chart LMS_2.jpg ├── LMS Lab Report.docx ├── Lab Project .zip └── README.md /FLow lms_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Basitx72/Library-Management-System/87969538d6d35911f8f9bdeb93ad477eb3710722/FLow lms_1.jpg -------------------------------------------------------------------------------- /Flow Chart LMS_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Basitx72/Library-Management-System/87969538d6d35911f8f9bdeb93ad477eb3710722/Flow Chart LMS_1.jpg -------------------------------------------------------------------------------- /Flow Chart LMS_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Basitx72/Library-Management-System/87969538d6d35911f8f9bdeb93ad477eb3710722/Flow Chart LMS_2.jpg -------------------------------------------------------------------------------- /LMS Lab Report.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Basitx72/Library-Management-System/87969538d6d35911f8f9bdeb93ad477eb3710722/LMS Lab Report.docx -------------------------------------------------------------------------------- /Lab Project .zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Basitx72/Library-Management-System/87969538d6d35911f8f9bdeb93ad477eb3710722/Lab Project .zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Library Management System 2 | ## Introduction 3 | Library management system is useful for the librarian to keep track of all the books. He can 4 | search the book in the library. This system helps the librarian to track the books that are being 5 | issued to the students or staff. 6 | 7 | ### Tasks 8 | - Add new book 9 | - Update book 10 | - Delete book 11 | - Issue book 12 | - Return book 13 | - Global book search 14 | 15 | ### Artifacts 16 | - Flow Chart 17 | - Report 18 | - Source Code 19 | ### Importing Modules 20 | ``` 21 | import datetime 22 | import pandas as pd 23 | 24 | df = pd.read_csv('Book1.csv') 25 | today = datetime.date.today() 26 | time_to_return = datetime.timedelta(days=14) # 14 days to return 27 | return_time = today + time_to_return 28 | structure = pd.DataFrame(df) 29 | pd.set_option('display.max_columns', None) 30 | pd.set_option('display.width', 1000) 31 | ``` 32 | 33 | Here we are importing 2 modules “datetime” and “pandas”. Datetime is used for handling time usage and getting the current time from the user. Then we import a .csv file and store the current time in ‘today’ variable. The ‘time_to_return’ variable adds 14 days as a result date whenever it is called. ‘pd.set_option’ is used to display the terminal correctly and prevent it from overlapping. 34 | 35 | ## Functions 36 | ### Add Book 37 | ```def add_book(): 38 | global structure 39 | global today 40 | book = input("Enter new book: ") 41 | row = input("Enter book placement(row,column): ") 42 | newbook = {'Book Name': book, 'Entry Date': today, 'Availability': 'Yes', 'Issue Date': 'None', 'Issued to': 'None', 43 | 'Return Date': 'None', 'Extra Charges': 0, 'Placement': row} 44 | structure = structure.append(newbook, ignore_index=True) 45 | ``` 46 | 47 | The add_book() function adds a new book in the DataFrame. Global variables are used so that any variable outside the function can be used inside the function as well. Then we take two inputs from the user for the book name and the placement of the book. Then using a Dictionary in which keys are column headers of a DataFrame, we append the entered data into the DataFrame. 48 | 49 | ### Issue Book 50 | ```def issue_book(): 51 | global structure 52 | global df 53 | print('-------------------------------------------------') 54 | print(structure) 55 | print('-------------------------------------------------') 56 | print('') 57 | book = input("What book do you want to issue?: ") 58 | if structure.loc[structure['Availability'] == 'No']: 59 | print("--") 60 | issue_person = input("Who do you want to issue the book to: ") 61 | if structure['Book Name'].str.contains(book).any(): 62 | structure.set_index('Book Name', inplace=True) 63 | structure.loc[book, 'Issue Date'] = today 64 | structure.loc[book, 'Availability'] = 'No' 65 | structure.loc[book, 'Issued To'] = issue_person 66 | structure.loc[book, 'Return Date'] = return_time 67 | structure.reset_index(inplace=True) 68 | print('-------------------------------------------------') 69 | print('Book issued Successfully') 70 | print('-------------------------------------------------') 71 | 72 | else: 73 | print('-------------------------------------------------') 74 | print("Wrong Input, Enter book index again!") 75 | print('-------------------------------------------------') 76 | issue_book() 77 | ``` 78 | 79 | The issue_book() function is used to issue a book to a person. It takes two inputs: one for the book name and the other for the person name it is issued to. 80 | 81 | ### Return Book 82 | ```def return_book(): 83 | global structure 84 | returned_book = input("Enter book name to return: ") 85 | if structure['Book Name'].str.contains(returned_book).any(): 86 | structure.set_index('Book Name', inplace=True) 87 | structure.loc[returned_book, 'Availability'] = 'Yes' 88 | structure.loc[returned_book, 'Issue Date'] = 'None' 89 | structure.loc[returned_book, 'Return Date'] = 'None' 90 | structure.loc[returned_book, 'Issued To'] = 'None' 91 | structure.reset_index(inplace=True) 92 | else: 93 | print('-------------------------------------------------') 94 | print('Invalid Book') 95 | print('-------------------------------------------------') 96 | print('Enter Again') 97 | return_book() 98 | ``` 99 | 100 | The return_book() function returns an issued book and sets all the columns to default values. 101 | 102 | ### Delete Book 103 | ```def delete_book(): 104 | global structure 105 | delete = input("Which book do you want to delete?: ") 106 | if structure['Book Name'].str.contains(delete).any(): 107 | structure.set_index('Book Name', inplace=True) 108 | structure = structure.drop(delete) 109 | structure.reset_index(inplace=True) 110 | else: 111 | print("Invalid Entry") 112 | print("Enter Again") 113 | delete_book() 114 | ``` 115 | 116 | The delete_book() function deletes a book from the DataFrame by deleting the row using drop function. Then we set the index to “Book Name” again so that we can take input from the user in a string. 117 | 118 | ### View Books Issued to a User 119 | ```def user_issued(): 120 | user = input("Enter user to view: ") 121 | global structure 122 | if structure['Issued To'].str.contains(user).any(): # Checks if the user is in the 'Issued To' box 123 | check = structure[structure['Issued To'] == user] 124 | print(check) 125 | else: 126 | print('No book issues to specifies person') 127 | print('') 128 | print('Enter again') 129 | user_issued() 130 | ``` 131 | 132 | The user_issued() function checks if the user is in the ‘Issued to’ column of the DataFrame and shows all the books issued to that user. 133 | 134 | ### Status of a Book 135 | ```def book_issued(): 136 | book = input("Enter Book to view: ") 137 | global structure 138 | if structure['Book Name'].str.contains(book).any(): 139 | check = structure[structure['Book Name'] == book] 140 | print(check) 141 | else: 142 | print('-------------------------------------------------') 143 | print('No book with the name', book, 'found in the database') 144 | print('-------------------------------------------------') 145 | print('Enter Again') 146 | book_issued() 147 | ``` 148 | 149 | The book_issued() function checks if the entered book is in the DataFrame. If it is, then it shows the status of the book e.g. it’s availability, the user this book is issued to, placement of the book and entry date. 150 | 151 | #### Note: 152 | > *Else Statements at the end of each function is used to call the function again if an invalid entry is entered.* 153 | 154 | ## Home Screen 155 | This the main code of the program where you are first welcomed by a welcome message and then using the while True infinite loop, we take inputs from user to choose. Each choice has its own function that it calls and if the choice entered is invalid, then the loop runs again. 156 | 157 | ### Welcome Screen 158 | ```print('-------------------------------------------------') 159 | print('- -') 160 | print('- Welcome to Library Management System -') 161 | print('- -') 162 | print('-------------------------------------------------') 163 | print('') 164 | ``` 165 | 166 | As you can here, You are first welcomed by this message. Then we run a while True infinite loop. 167 | 168 | ### While True Loop 169 | ```while True: 170 | 171 | print(""" Enter 'A' to add a new book 172 | Enter 'I' to issue a book 173 | Enter 'U' to view issued books to the user 174 | Enter 'R' to return a book 175 | Enter 'V' to view available books 176 | Enter 'B' to view status of a book 177 | Enter 'D' to view database 178 | Enter 'X' to delete a book 179 | Enter 'Q' to exit 180 | Enter 'S' to save file""") 181 | 182 | print('-------------------------------------------------') 183 | choice = input("What would you like to do: ") 184 | print('-------------------------------------------------') 185 | if choice == 'A': 186 | add_book() 187 | print(structure) 188 | print('-------------------------------------------------') 189 | elif choice == 'I': 190 | issue_book() 191 | print('-------------------------------------------------') 192 | elif choice == 'U': 193 | user_issued() 194 | print('-------------------------------------------------') 195 | elif choice == 'R': 196 | return_book() 197 | print('-------------------------------------------------') 198 | elif choice == 'B': 199 | 200 | book_issued() 201 | print('-------------------------------------------------') 202 | elif choice == 'D': 203 | print(structure) 204 | print('-------------------------------------------------') 205 | elif choice == 'X': 206 | delete_book() 207 | print('-------------------------------------------------') 208 | elif choice == 'V': 209 | available() 210 | print('-------------------------------------------------') 211 | ``` 212 | 213 | Here what choice ‘D’ does is, it prints the whole DataFrame with all the books and information in it. 214 | ```elif choice == 'S': 215 | structure.to_csv('Book1.csv', index=False) 216 | count = count + 1 217 | elif choice == 'Q': 218 | if count == 0: 219 | print("You have not saved your work. Do you want to exit anyways?:") 220 | decision = input(">") 221 | if decision == 'Yes': 222 | break 223 | else: 224 | continue 225 | else: 226 | break 227 | else: 228 | print('-------------------------------------------------') 229 | print('Invalid choice, Choose again') 230 | print('-------------------------------------------------') 231 | 232 | print("Good Bye") 233 | ``` 234 | 235 | At the end, if the user wants to quit, the count variable is used to check if the user has saved the work or not. When user calls the save function, the count is added by 1 and the program breaks out of the loop and exits. 236 | 237 | ### Our Motive 238 | > ***The reason behind this code is that we wanted to create a system where you can manage and add data in it and upon looking at the library management system, we found it to be very interesting. We wanted to design a program where you can have all your data in a single frame, save the new entered data and is also capable of performing all the other library management system related functions.*** 239 | 240 | ## Raw Code 241 | ``` import datetime 242 | import pandas as pd 243 | 244 | df = pd.read_csv('Book1.csv') 245 | today = datetime.date.today() 246 | time_to_return = datetime.timedelta(days=14) # 14 days to return 247 | return_time = today + time_to_return 248 | structure = pd.DataFrame(df) 249 | pd.set_option('display.max_columns', None) 250 | pd.set_option('display.width', 1000) 251 | count = 0 252 | 253 | 254 | def add_book(): 255 | global structure 256 | global today 257 | book = input("Enter new book: ") 258 | row = input("Enter book placement(row,column): ") 259 | newbook = {'Book Name': book, 'Entry Date': today, 'Availability': 'Yes', 'Issue Date': 'None', 'Issued to': 'None', 260 | 'Return Date': 'None', 'Extra Charges': 0, 'Placement': row} 261 | structure = structure.append(newbook, ignore_index=True) 262 | 263 | 264 | def issue_book(): 265 | global structure 266 | global df 267 | print('------------------------------') 268 | print(structure) 269 | print('------------------------------') 270 | print('') 271 | book = input("What book do you want to issue?: ") 272 | issue_person = input("Who do you want to issue the book to: ") 273 | if structure['Book Name'].str.contains(book).any(): 274 | structure.set_index('Book Name', inplace=True) 275 | structure.loc[book, 'Issue Date'] = today 276 | structure.loc[book, 'Availability'] = 'No' 277 | structure.loc[book, 'Issued To'] = issue_person 278 | structure.loc[book, 'Return Date'] = return_time 279 | structure.reset_index(inplace=True) 280 | print('------------------------------') 281 | print('Book issued Successfully') 282 | print('------------------------------') 283 | 284 | else: 285 | print('------------------------------') 286 | print("Wrong Input, Enter book index again!") 287 | print('------------------------------') 288 | issue_book() 289 | 290 | 291 | def user_issued(): 292 | user = input("Enter user to view: ") 293 | global structure 294 | if structure['Issued To'].str.contains(user).any(): # Checks if the user is in the 'Issued To' box 295 | check = structure[structure['Issued To'] == user] 296 | print(check) 297 | else: 298 | print('No book issues to specifies person') 299 | print('') 300 | print('Enter again') 301 | user_issued() 302 | 303 | 304 | def book_issued(): 305 | book = input("Enter Book to view: ") 306 | global structure 307 | if structure['Book Name'].str.contains(book).any(): 308 | check = structure[structure['Book Name'] == book] 309 | print(check) 310 | else: 311 | print('------------------------------') 312 | print('No book with the name', book, 'found in the database') 313 | print('------------------------------') 314 | print('Enter Again') 315 | book_issued() 316 | 317 | 318 | def return_book(): 319 | global structure 320 | returned_book = input("Enter book name to return: ") 321 | if structure['Book Name'].str.contains(returned_book).any(): 322 | structure.set_index('Book Name', inplace=True) 323 | structure.loc[returned_book, 'Availability'] = 'Yes' 324 | structure.loc[returned_book, 'Issue Date'] = 'None' 325 | structure.loc[returned_book, 'Return Date'] = 'None' 326 | structure.loc[returned_book, 'Issued To'] = 'None' 327 | structure.reset_index(inplace=True) 328 | else: 329 | print('------------------------------') 330 | print('Invalid Book') 331 | print('------------------------------') 332 | print('Enter Again') 333 | return_book() 334 | 335 | 336 | def available(): 337 | global structure 338 | print(structure[structure['Availability'] == 'Yes']) 339 | 340 | 341 | def delete_book(): 342 | global structure 343 | delete = input("Which book do you want to delete?: ") 344 | if structure['Book Name'].str.contains(delete).any(): 345 | structure.set_index('Book Name', inplace=True) 346 | structure = structure.drop(delete) 347 | structure.reset_index(inplace=True) 348 | else: 349 | print("Invalid Entry") 350 | print("Enter Again") 351 | delete_book() 352 | 353 | 354 | print('-------------------------------------------------') 355 | print('- -') 356 | print('- Welcome to Library Management System -') 357 | print('- -') 358 | print('-------------------------------------------------') 359 | print('') 360 | 361 | while True: 362 | 363 | print(""" Enter 'A' to add a new book 364 | Enter 'I' to issue a book 365 | Enter 'U' to view issued books to the user 366 | Enter 'R' to return a book 367 | Enter 'V' to view available books 368 | Enter 'B' to view status of a book 369 | Enter 'D' to view database 370 | Enter 'X' to delete a book 371 | Enter 'Q' to exit 372 | Enter 'S' to save file""") 373 | 374 | print('-------------------------------------------------') 375 | choice = input("What would you like to do: ") 376 | print('-------------------------------------------------') 377 | if choice == 'A': 378 | add_book() 379 | print(structure) 380 | print('-------------------------------------------------') 381 | elif choice == 'I': 382 | issue_book() 383 | print('-------------------------------------------------') 384 | elif choice == 'U': 385 | user_issued() 386 | print('-------------------------------------------------') 387 | elif choice == 'R': 388 | return_book() 389 | print('-------------------------------------------------') 390 | elif choice == 'B': 391 | 392 | book_issued() 393 | print('-------------------------------------------------') 394 | elif choice == 'D': 395 | print(structure) 396 | print('-------------------------------------------------') 397 | elif choice == 'X': 398 | delete_book() 399 | print('-------------------------------------------------') 400 | elif choice == 'V': 401 | available() 402 | print('-------------------------------------------------') 403 | elif choice == 'S': 404 | structure.to_csv('Book1.csv', index=False) 405 | count = count + 1 406 | elif choice == 'Q': 407 | if count == 0: 408 | print("You have not saved your work. Do you want to exit anyways?:") 409 | decision = input(">") 410 | if decision == 'Yes': 411 | break 412 | else: 413 | continue 414 | else: 415 | break 416 | else: 417 | print('-------------------------------------------------') 418 | print('Invalid choice, Choose again') 419 | print('-------------------------------------------------') 420 | 421 | print("Good Bye") 422 | ``` 423 | 424 | 425 | ![Flow Chart LMS_1](https://user-images.githubusercontent.com/72499151/157419274-9ecbf25c-e9c7-45b3-b26e-7af4ce6f8c4f.jpg) 426 | ![FLow lms_1](https://user-images.githubusercontent.com/72499151/157419223-40bf362a-ccfa-4a22-a363-58e22ca6deb1.jpg) 427 | ![Flow Chart LMS_2](https://user-images.githubusercontent.com/72499151/157419286-5a2ddd98-dfea-465f-a448-b7158cf8d147.jpg) 428 | --------------------------------------------------------------------------------