Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Book:
- def __init__(self, author: str, name: str, publisher: str, year: int, page_num: int):
- self.author = author
- self.name = name
- self.publisher = publisher
- self.year = year
- self.page_num = page_num
- def __str__(self):
- return f'{self.author}, {self.name}, {self.publisher}, {self.year}, {self.page_num}'
- # Неважливо який ліст, головне щоб знизу була коректна логіка для їх фільтрування
- book_list = [Book('TNU', 'A VERY INTERSTING BOOK', 'A RANDOM GUY', 1932, 100),
- Book('TNU', 'ANOTHER INTERISTING BOOK', 'SUBURBIAN CITIZENS', 1999, 50)]
- inp = input('How would you like to filter your books?\n'
- 'Type 1 to filter them by author.\n'
- 'Type 2 to filter them by publisher.\n'
- 'Type 3 to filter to them by date.\n')
- result = []
- match inp:
- case '1':
- author = input('Type the author name >>> ')
- result = [book for book in book_list if book.author == author]
- case '2':
- publisher = input('Type the publisher name >>> ')
- result = [book for book in book_list if book.publisher == publisher]
- case '3':
- year = ''
- while not year.isdigit():
- year = input('Type the year after which to show the books >>> ')
- year = int(year)
- result = [book for book in book_list if book.year > year]
- if result:
- print(*result, sep='\n')
- else:
- print('Found nothing')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement