Создать класс товара содержащий статистические методы, перевод в доллары, перевод в…
- User
Создать класс товара содержащий статистические методы, перевод в доллары, перевод в евро. Открытые поля: название, цена закупки, цена продажи, количество купленных товаров, количество проданного товара. Нестатические методы: вычисление выручки, вычисление прибыли, вывод полной информации о товаре
- Assistant
class Product: def init(self, name, purchase_price, selling_price, quantity_purchased, quantity_sold): self.name = name self.purchase_price = float(purchase_price) self.selling_price = float(selling_price) self.quantity_purchased = int(quantity_purchased) self.quantity_sold = int(quantity_sold)
def revenue(self): return self.selling_price * self.quantity_sold def profit(self): return (self.selling_price - self.purchase_price) * self.quantity_sold def info(self): print(f"Product name: {self.name}") print(f"Purchase price: ${self.purchase_price}") print(f"Selling price: ${self.selling_price}") print(f"Quantity purchased: {self.quantity_purchased}") print(f"Quantity sold: {self.quantity_sold}") print(f"Revenue: ${self.revenue()}") print(f"Profit: ${self.profit()}") def to_usd(self): return self.selling_price / 1.21 def to_eur(self): return self.selling_price / 0.83product1 = Product("Shoes", "50", "100", "100", "50") product1.info()
print(f"Selling price in USD: ${product1.to_usd()}")
print(f"Selling price in EUR: €{product1.to_eur()}")