Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions Start/Ch 2/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~~~~~~~~~
Expand Down