Advertisement
Dimitar_Borisov

Digital Book Collection Manager

Jun 2nd, 2025
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.17 KB | None | 0 0
  1. titles = []      # List of book titles
  2. authors = []     # List of book authors
  3. statuses = []    # List of read statuses: "Read" or "Unread"
  4.  
  5.  
  6. def add_book(title, author):
  7.     titles.append(title)
  8.     authors.append(author)
  9.     statuses.append("Unread")
  10.     print("The book is added.")
  11.  
  12.  
  13. def mark_as_read(title):
  14.     for i in range(len(titles)):
  15.         if titles[i] == title:
  16.             statuses[i] = "Read"
  17.             print("The book has been read.")
  18.         else:
  19.             print("Error. The book is not found.")
  20.  
  21.  
  22. def mark_as_unread(title):
  23.     for i in range(len(titles)):
  24.         if titles[i] == title:
  25.             statuses[i] = "Unread"
  26.             print("The book has not been read.")
  27.         else:
  28.             print("Error. The book is not found.")
  29.  
  30.  
  31. def search_book(keyword):
  32.     writer = ""
  33.     wrote = ""
  34.     word = keyword.casefold()
  35.     if word in titles or word in authors:
  36.         for i in range(len(titles)):
  37.             if titles[i] == word:
  38.                 wrote = titles[i]
  39.                 writer = authors[i]
  40.                 print(f"{writer} - '{wrote}'")
  41.                
  42.             elif authors[i] == word:
  43.                 wrote = titles[i]
  44.                 writer = authors[i]
  45.                 print(f"{writer} - '{wrote}'")
  46.  
  47.             else:
  48.                 print("No books found.")
  49.  
  50.  
  51. def list_books():
  52.     writer = ""
  53.     wrote = ""
  54.     status = ""
  55.  
  56.     for i in range(len(titles)):
  57.         writer = authors[i]
  58.         wrote = titles[i]
  59.         status = statuses[i]
  60.         print(f"{writer} - '{wrote}' : {status}")
  61.  
  62.  
  63. def suggest_book():
  64.     import random
  65.  
  66.     book_list = []
  67.  
  68.     for i in range(len(statuses)):
  69.         if statuses[i] == "Unread":
  70.             book_list.append(i)
  71.  
  72.     if not book_list:
  73.         print("No unread books left.")
  74.     else:
  75.         authors_list = []
  76.         titles_list = []
  77.  
  78.         for i in book_list:
  79.             for j in range(len(authors)):
  80.                 authors_list.append(authors[int(i)])
  81.             for k in range(len(titles)):
  82.                 titles_list.append(titles[int(i)])
  83.         matrix_of_books = []
  84.  
  85.         for i in authors_list:
  86.             for j in titles_list:
  87.                 matrix_of_books.append([i, j])
  88.  
  89.         random_book = random.choice(matrix_of_books)
  90.         some_book = f"'{random_book[0]}' - {random_book[1]}"
  91.         print(some_book)
  92.  
  93.  
  94. def delete_book(title):
  95.     if title in titles:
  96.         index = titles.index(title)
  97.         del titles[index]
  98.         del authors[index]
  99.         del statuses[index]
  100.         print("The book has been deleted.")
  101.     else:
  102.         print("Book not found.")
  103.  
  104.  
  105. def main():
  106.     print("📚 Welcome to the Digital Book Collection Manager 📚\n")
  107.  
  108.     while True:
  109.         print("\nPlease choose an option:")
  110.         print("1. Add a new book")
  111.         print("2. Mark a book as read")
  112.         print("3. Mark a book as unread")
  113.         print("4. Search for a book")
  114.         print("5. List all books")
  115.         print("6. Suggest a book to read")
  116.         print("7. Delete a book")
  117.         print("8. Exit")
  118.  
  119.         choice = input("\nEnter your choice (1-8): ")
  120.  
  121.         if choice == '1':
  122.             title = input("Enter the book title: ")
  123.             author = input("Enter the author's name: ")
  124.             add_book(title, author)
  125.  
  126.         elif choice == '2':
  127.             title = input("Enter the title of the book to mark as read: ")
  128.             mark_as_read(title)
  129.  
  130.         elif choice == '3':
  131.             title = input("Enter the title of the book to mark as unread: ")
  132.             mark_as_unread(title)
  133.  
  134.         elif choice == '4':
  135.             keyword = input("Enter a keyword to search: ")
  136.             search_book(keyword)
  137.  
  138.         elif choice == '5':
  139.             list_books()
  140.  
  141.         elif choice == '6':
  142.             suggest_book()
  143.  
  144.         elif choice == '7':
  145.             title = input("Enter the title of the book to delete: ")
  146.             delete_book(title)
  147.  
  148.         elif choice == '8':
  149.             print("Goodbye! Happy reading! 📖")
  150.             break
  151.  
  152.         else:
  153.             print("Invalid option. Please choose a number from 1 to 8.")
  154.  
  155.  
  156. if __name__ == "__main__":
  157.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement