Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Book:
- def __init__(self, book_id, title, author, genre, year, copies):
- self.book_id = book_id
- self.title = title
- self.author = author
- self.genre = genre
- self.year = year
- self.copies = copies
- def display_info(self):
- print(f"Book ID: {self.book_id}")
- print(f"Title: {self.title}")
- print(f"Author: {self.author}")
- print(f"Genre: {self.genre}")
- print(f"Year: {self.year}")
- def add_books(books_list, book):
- books_list.append(book)
- def sort_by_oldest_year(books_list):
- sorted_books = sorted(books_list, key=lambda book: book.year, reverse = True)
- for book in sorted_books:
- book.display_info()
- def serach_by_author_title(books_list, author, title):
- found = False
- for book in books_list:
- if book.author == author and book.title == title:
- found = True
- book.display_info()
- break
- if not found:
- print("Book not found!!!")
- def filter_by_genre(books_list, genre):
- for book in books_list:
- if book.genre == genre:
- book.display_info()
- def check_copies(books_list, author, title):
- for book in books_list:
- if book.author == author and book.title == title:
- if book.copies > 0:
- print(f"{book.copies} left.")
- else:
- print("No copies left.")
- books_list = []
- books = int(input())
- for _ in range(books):
- book_id = int(input())
- title = input()
- author = input()
- genre = input()
- year = int(input())
- copies = int(input())
- book = Book(book_id, title, author, genre, year, copies)
- books_list.append(book)
- while True:
- print("1. Добавяне на книга")
- print("2. Сортиране по година")
- print("3. Търсене на книга по заглавие и автор")
- print("4. Филтриране по жанр")
- print("5. Проверка на копия")
- print("6. Изход")
- choice = int(input())
- match choice:
- case 1:
- book_id = int(input())
- title = input()
- author = input()
- genre = input()
- year = int(input())
- copies = int(input())
- book_to_add = Book(book_id, title, author, genre, year, copies)
- books_list.append(book_to_add)
- print(books_list)
- case 2:
- sort_by_oldest_year(books_list)
- case 3:
- author = input()
- title = input()
- serach_by_author_title(books_list, author, title)
- case 4:
- genre = input()
- filter_by_genre(books_list, genre)
- case 5:
- author = input()
- title = input()
- check_copies(books_list, author, title)
- case 6:
- break
- case _:
- print("Wrong option!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement