Yanam

Untitled

Aug 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. class Book:
  2.     def __init__(self, title: str, author: str, price: float, chapters: list):
  3.         self.title = title
  4.         self.author = author
  5.         self.price = float(price)
  6.         self.chapters = chapters
  7.  
  8.  
  9.  
  10. books = []
  11.  
  12. while True:
  13.     data_list = input()
  14.     if data_list == 'on work':
  15.         break
  16.     try:
  17.         data = data_list.split(' -> ')[0]
  18.         title = data.split()[0]
  19.         author = data.split()[1]
  20.         price = data.split()[2]
  21.         if float(price) <= 0:
  22.             raise Exception
  23.         chap = data_list.split(' -> ')[1]
  24.         chapters = chap.split(', ')
  25.         book = Book(title, author, price, chapters)
  26.         books.append(book)
  27.     except:
  28.         continue
  29.  
  30. sold_books = []
  31. while True:
  32.     request = input()
  33.  
  34.     if request == 'end work':
  35.         break
  36.     titles = list(map(lambda bk: bk.title, books))
  37.  
  38.     if request not in titles:
  39.         print(f'No such book here')
  40.     else:
  41.         bk = list(filter(lambda b: b.title == request, books))[0]
  42.         sold_books.append(bk)
  43.  
  44. if request == 'end work':
  45.     # sold_list = list(filter(lambda bk: bk.sold is True, books))
  46.     if len(sold_books) == 0:
  47.         print('Bad day :(')
  48.         exit(0)
  49.     price = list(map(lambda pr: pr.price, sold_books))
  50.     price = list(map(float, price))
  51.  
  52.     for book in sold_books:
  53.         print(f'SOLD: {book.title} with author {book.author}. Chapters in the book {len(book.chapters)}')
  54.     print(f'Money: {sum(price):.2f}')
Advertisement
Add Comment
Please, Sign In to add comment