From 222b3749d7e130ac75a249a31999c53f04f9be0c Mon Sep 17 00:00:00 2001 From: Touhidul Haider <163761310+TouhidulHaider@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:48:44 +0600 Subject: [PATCH] ch3_challenge.py --- Start/Ch 3/challenge.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Start/Ch 3/challenge.py b/Start/Ch 3/challenge.py index 679db2b..3bb6e99 100644 --- a/Start/Ch 3/challenge.py +++ b/Start/Ch 3/challenge.py @@ -23,6 +23,12 @@ def __init__(self, ticker, price, company): self.company = company self.ticker = ticker + def __str__(self): + return f"{self.ticker}: {self.company_name} -- ${self.price}" + + def __lt__(self, other): + return self.price < other.price + class Bond(Asset): def __init__(self, price, description, duration, yieldamt): @@ -31,6 +37,12 @@ def __init__(self, price, description, duration, yieldamt): self.duration = duration self.yieldamt = yieldamt + def __str__(self): + return f"{self.description}: {self.duration}yr : ${self.price} : {self.yieldamt}%" + + def __lt__(self, other): + return self.yieldamt < other.yieldamt + # ~~~~~~~~~ TEST CODE ~~~~~~~~~ stocks = [