Dec-12-2021, 07:14 PM
Hi! I can the below code, I want to calculate de total price of copies for a book
class Library(): def __init__(self, name) -> None: self.book = {} self.name = name self.stock = ' ' def lista_of_books(self): return self.book def append_book(self, title, author, copies, price): self.book.update(titlu=title, autor=author, exemplare=copies, pret1=price) def total_price_of_copies(self, title): for key,value in self.book.items(): if self.book[key] == title: print('Pretul pentru toate exemplarele din', title, self.book['exemplare1'] * self.book['pret1']) break class Book(): def __init__(self, title, author, copies, price): self.titlu = title self.autor = author self.exemplare = copies self.pret = price a = Library('Alexandria') a.append_book('Howls moving castle', 'Diana Wynne Jones', 8, 33) a.append_book('Graffiti Moon', 'Cath Crowley', 5, 28) a.append_book('All the Bright Places', 'Jennifer Niven', 7, 15) a.total_price_of_copies('Howls moving castle')