Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Book:
- def __init__(self, title: str, author: str, price: float, chapters: list):
- self.title = title
- self.author = author
- self.price = float(price)
- self.chapters = chapters
- books = []
- while True:
- data_list = input()
- if data_list == 'on work':
- break
- try:
- data = data_list.split(' -> ')[0]
- title = data.split()[0]
- author = data.split()[1]
- price = data.split()[2]
- if float(price) <= 0:
- raise Exception
- chap = data_list.split(' -> ')[1]
- chapters = chap.split(', ')
- book = Book(title, author, price, chapters)
- books.append(book)
- except:
- continue
- sold_books = []
- while True:
- request = input()
- if request == 'end work':
- break
- titles = list(map(lambda bk: bk.title, books))
- if request not in titles:
- print(f'No such book here')
- else:
- bk = list(filter(lambda b: b.title == request, books))[0]
- sold_books.append(bk)
- if request == 'end work':
- # sold_list = list(filter(lambda bk: bk.sold is True, books))
- if len(sold_books) == 0:
- print('Bad day :(')
- exit(0)
- price = list(map(lambda pr: pr.price, sold_books))
- price = list(map(float, price))
- for book in sold_books:
- print(f'SOLD: {book.title} with author {book.author}. Chapters in the book {len(book.chapters)}')
- print(f'Money: {sum(price):.2f}')
Advertisement
Add Comment
Please, Sign In to add comment