From 3d10429c7a75666611b4c9bdf6996f2847151965 Mon Sep 17 00:00:00 2001 From: Touhidul Haider <163761310+TouhidulHaider@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:35:58 +0600 Subject: [PATCH] ch2_challenge.py --- Start/Ch 2/challenge.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Start/Ch 2/challenge.py b/Start/Ch 2/challenge.py index 556fd1f..32c0cdb 100644 --- a/Start/Ch 2/challenge.py +++ b/Start/Ch 2/challenge.py @@ -12,14 +12,32 @@ # For stocks: "Ticker: Company -- $Price" # For bonds: "description: duration'yr' : $price : yieldamt%" -class Asset(): - pass +class Asset(ABC): + def __init__(self, price): + self.price = price -class Stock(): - pass + @abstractmethod + def get_description(self): + pass -class Bond(): - pass +class Stock(Asset): + def __init__(self, ticker, price, company_name): + super().__init__(price) + self.ticker = ticker + self.company_name = company_name + + def get_description(self): + return f"{self.ticker}: {self.company_name} -- ${self.price}" + +class Bond(Asset): + def __init__(self, price, description, duration, yieldamt): + super().__init__(price) + self.description = description + self.duration = duration + self.yieldamt = yieldamt + + def get_description(self): + return f"{self.description}: {self.duration}yr : ${self.price} : {self.yieldamt}%" # ~~~~~~~~~ TEST CODE ~~~~~~~~~