Python: module bookstore
/home/kali/bookstore.py
Classes
class Bookstore(builtins.object)
A bookstore class to hold books' names, their authors, and costs.

Attributes:
books : list
    A list containing the books in the bookstore. Each book is represented as a tuple containing its name, author, and cost.
__init__(self)
Initializes an empty bookstore.
add_book(self, bookname: str, author: str, cost: float)
Adds a new book to the bookstore.
Parameters:
bookname : str
The name of the book.
author : str
The author of the book.
cost : float
The cost of the book.
Returns:
None
print_current_books(self)
Prints the current list of books in the bookstore.
remove_book(self, bookname: str)
Removes a book from the bookstore by its name.
Parameters:
bookname : str
The name of the book to be removed.
Raises:
ValueError
If the book doesn't exist in the bookstore.
search_for_book(self, bookname: str) → list
Searches for a book by its name and returns a list of matching books.
Parameters:
bookname : str
The name of the book to be searched.
Returns:
list
A list of books that match the search criteria.
Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
Usage Example
from bookstore import Bookstore

# Create a bookstore instance
store = Bookstore()

# Add some books
store.add_book("Python Crash Course", "Eric Matthes", 39.99)
store.add_book("Fluent Python", "Luciano Ramalho", 64.99)
store.add_book("Effective Python", "Brett Slatkin", 44.95)

# Print all books
store.print_current_books()

# Search for a book
results = store.search_for_book("Python")
print(f"Found {len(results)} books matching 'Python'")

# Remove a book
store.remove_book("Fluent Python")
store.print_current_books()