Version 1.1
- Project Abstract
- Business Requirements
- Constraints
- Template Code Structure
- Execution Steps to Follow
Riverside Public Library requires a book management system to maintain their expanding collection. The system will catalog books, track availability, and generate reports using Python's list comprehension and related operations. This console application demonstrates advanced list comprehension techniques while allowing librarians to efficiently manage the library's collection. The system performs critical functions including categorizing books by genre, filtering by availability, transforming book data, and calculating collection statistics. By implementing these operations with Python list comprehension, the system provides an efficient way for library staff to organize and analyze their collection.
- System needs to store and categorize different genres of books (fiction, non-fiction, reference, children's, biography)
- System must support filtering books by genre, availability, publication decade, or keyword
- Console should handle different list comprehension operations:
- Basic filtering (books by genre, availability)
- Transforming data (formatting titles, creating citation strings)
- Nested list comprehension (for multi-criteria filtering)
- List comprehension with conditionals (if-else structures)
-
Book Records:
- Must be stored as dictionaries with fields for id, title, author, genre, publication_year, available, popularity_score
- Must be stored in list variable
books
- Example:
{"id": "B001", "title": "Python Fundamentals", "author": "John Smith", "genre": "reference", "publication_year": 2019, "available": True, "popularity_score": 4.5}
-
Book Genres:
- Must be one of: "fiction", "non-fiction", "reference", "children", "biography"
- Must be stored as string in book's "genre" field
- Example: "fiction"
-
Availability Status:
- Must be stored as boolean in "available" field
- Must be True (available) or False (on loan)
- Example: True
-
Popularity Score:
- Must be stored as float in "popularity_score" field
- Must be between 1.0-5.0
- Example: 4.5
-
Predefined Books:
- Must use these exact predefined books in the initial book list:
{"id": "B001", "title": "Python Fundamentals", "author": "John Smith", "genre": "reference", "publication_year": 2019, "available": True, "popularity_score": 4.5}
{"id": "B002", "title": "Mystery at Midnight", "author": "Jane Doe", "genre": "fiction", "publication_year": 2018, "available": False, "popularity_score": 4.2}
{"id": "B003", "title": "History of Computing", "author": "Alan Turing", "genre": "non-fiction", "publication_year": 2015, "available": True, "popularity_score": 3.8}
{"id": "B004", "title": "The Dragon's Quest", "author": "Emily Johnson", "genre": "children", "publication_year": 2020, "available": True, "popularity_score": 4.7}
{"id": "B005", "title": "Life of Einstein", "author": "Robert Brown", "genre": "biography", "publication_year": 2017, "available": False, "popularity_score": 4.1}
- Must use these exact predefined books in the initial book list:
-
New Arrivals:
- Must use these exact predefined items in the new arrivals list:
{"id": "N001", "title": "Data Science Handbook", "author": "Sarah Miller", "genre": "reference", "publication_year": 2023, "available": True, "popularity_score": 4.9}
{"id": "N002", "title": "Quantum Physics Simplified", "author": "Richard Feynman", "genre": "non-fiction", "publication_year": 2022, "available": True, "popularity_score": 4.3}
- Must use these exact predefined items in the new arrivals list:
-
Book List Combination:
- Must use list comprehension to combine lists with additional transformation
- Example:
[{**book, "section": "New"} for book in new_arrivals]
-
Book Filtering by Genre:
- Must use list comprehension
- Example:
[book for book in books if book["genre"] == "fiction"]
-
Available Books Filtering:
- Must use list comprehension
- Example:
[book for book in books if book["available"] == True]
-
Book Title Transformation:
- Must use list comprehension with string operations
- Example:
[book["title"].upper() for book in books]
-
Multi-criteria Filtering:
- Must use list comprehension with multiple conditions
- Example:
[book for book in books if book["genre"] == "reference" and book["available"] == True]
-
Book Publication Decade Filtering:
- Must use list comprehension with calculated conditions
- Example:
[book for book in books if book["publication_year"] // 10 == 201]
(for 2010s)
-
Book Citation Generation:
- Must use list comprehension with formatted strings
- Example:
[f"{book['author']} ({book['publication_year']}). {book['title']}." for book in books]
-
Conditional Transformation:
- Must use list comprehension with if-else
- Example:
[book["title"] if book["available"] else f"{book['title']} (ON LOAN)" for book in books]
-
Genre Count Calculation:
- Must use list comprehension with counting operations
- Example:
len([book for book in books if book["genre"] == "fiction"])
-
Average Popularity Calculation:
- Must use list comprehension with statistical operations
- Example:
sum([book["popularity_score"] for book in books]) / len(books)
-
Display Format:
- Show book ID, title, author, genre, publication year, availability, popularity score
- Format availability with "Available" or "On Loan" indicator
- Format popularity with star rating (★)
- Each book must be displayed on a new line
-
Required Output Format:
- Must show in this order:
- Show "===== LIBRARY BOOK MANAGEMENT SYSTEM ====="
- Show "Total Books: {count}"
- Show "Available Books: {count}"
- Show "Current Book Collection:"
- Show books with format: "{id} | {title} | {author} | {genre} | {year} | {availability} | Rating: {stars}"
- Show "Filtered Results:" when displaying search results
- Must show in this order:
-
Data Management Functions:
initialize_data()
- creates the initial book and new arrivals lists
-
List Comprehension Functions:
filter_by_genre(books, genre)
- filters books by genre using list comprehensionfilter_by_availability(books, available)
- filters books by availabilityfilter_by_decade(books, decade)
- filters books by publication decadefilter_by_keyword(books, keyword)
- filters books by keyword in title or authortransform_titles(books, case)
- transforms book titles to specified casegenerate_citations(books)
- generates formatted citations for booksget_book_availability(books)
- creates list with availability indicatorscalculate_genre_counts(books)
- counts books in each genrecalculate_average_popularity(books)
- calculates average popularityintegrate_new_arrivals(books, new_arrivals)
- combines book lists with transformation
-
Display Functions:
get_formatted_book(book)
- formats a book for displaydisplay_data(data, data_type)
- displays books or other data types
-
Program Control:
main()
- main program function
- Run the program
- View the main menu
- Select operations:
- Option 1: View Books
- Option 2: Filter Books
- Option 3: Transform Data
- Option 4: Generate Statistics
- Option 5: Integrate New Arrivals
- Option 0: Exit
- Perform operations on the book list
- View results after each operation
- Exit program when finished