Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Automated Library Management Script #969

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions library_management/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Automated Library Management System

## Description
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.

## Features
- Add new book records.
- Delete existing book records.
- Check out and return books.
- Display the current status of all books in the library.

## How to Use
1. Clone the repository and navigate to the `library_management` directory.
2. Run the script using Python:
```bash
python library_management.py
56 changes: 56 additions & 0 deletions library_management/library_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# library_management.py

library_records = []


def add_book(title, author, year):
book = {
"title": title, "author": author, "year": year, "status": "available"
}
library_records.append(book)
print(f'Book "{title}" added successfully!')


def delete_book(title):
global library_records
library_records = [
book for book in library_records if book["title"] != title
]
print(f'Book "{title}" deleted successfully!')


def checkout_book(title):
for book in library_records:
if book["title"] == title and book["status"] == "available":
book["status"] = "checked out"
print(f'You have checked out "{title}".')
return
print(f'Book "{title}" is not available.')


def return_book(title):
for book in library_records:
if book["title"] == title and book["status"] == "checked out":
book["status"] = "available"
print(f'You have returned "{title}".')
return
print(f'Book "{title}" is not checked out.')


def display_books():
print("Library Records:")
for book in library_records:
print(f'Title: {book["title"]}, Author: {book["author"]}, '
f'Year: {book["year"]}, Status: {book["status"]}')


if __name__ == "__main__":
add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
add_book("To Kill a Mockingbird", "Harper Lee", 1960)
display_books()
checkout_book("The Great Gatsby")
display_books()
return_book("The Great Gatsby")
display_books()
delete_book("To Kill a Mockingbird")
display_books()
656 changes: 656 additions & 0 deletions library_management/requirements.txt

Large diffs are not rendered by default.