Skip to content

Commit 5a8bf3c

Browse files
author
Vineeth Sai
committed
Added Automated Library Management script
1 parent 0fa47cd commit 5a8bf3c

File tree

3 files changed

+728
-0
lines changed

3 files changed

+728
-0
lines changed

library_management/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Automated Library Management System
2+
3+
## Description
4+
This Python script automates library management tasks such as adding, deleting, and checking out books. It keeps a record of the library's books and their availability status.
5+
6+
## Features
7+
- Add new book records.
8+
- Delete existing book records.
9+
- Check out and return books.
10+
- Display the current status of all books in the library.
11+
12+
## How to Use
13+
1. Clone the repository and navigate to the `library_management` directory.
14+
2. Run the script using Python:
15+
```bash
16+
python library_management.py
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# library_management.py
2+
3+
library_records = []
4+
5+
6+
def add_book(title, author, year):
7+
book = {
8+
"title": title, "author": author, "year": year, "status": "available"
9+
}
10+
library_records.append(book)
11+
print(f'Book "{title}" added successfully!')
12+
13+
14+
def delete_book(title):
15+
global library_records
16+
library_records = [
17+
book for book in library_records if book["title"] != title
18+
]
19+
print(f'Book "{title}" deleted successfully!')
20+
21+
22+
def checkout_book(title):
23+
for book in library_records:
24+
if book["title"] == title and book["status"] == "available":
25+
book["status"] = "checked out"
26+
print(f'You have checked out "{title}".')
27+
return
28+
print(f'Book "{title}" is not available.')
29+
30+
31+
def return_book(title):
32+
for book in library_records:
33+
if book["title"] == title and book["status"] == "checked out":
34+
book["status"] = "available"
35+
print(f'You have returned "{title}".')
36+
return
37+
print(f'Book "{title}" is not checked out.')
38+
39+
40+
def display_books():
41+
print("Library Records:")
42+
for book in library_records:
43+
print(f'Title: {book["title"]}, Author: {book["author"]}, '
44+
f'Year: {book["year"]}, Status: {book["status"]}')
45+
46+
47+
if __name__ == "__main__":
48+
add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
49+
add_book("To Kill a Mockingbird", "Harper Lee", 1960)
50+
display_books()
51+
checkout_book("The Great Gatsby")
52+
display_books()
53+
return_book("The Great Gatsby")
54+
display_books()
55+
delete_book("To Kill a Mockingbird")
56+
display_books()

0 commit comments

Comments
 (0)