From c3fb143bb0191ef73a26dc44f840406d9b3dc14a Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 11:22:51 -0700 Subject: [PATCH 01/19] Update settings.json --- .vscode/settings.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 32dee9a..74e879f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,9 +17,8 @@ "files.autoSave": "afterDelay", "screencastMode.onlyKeyboardShortcuts": true, "terminal.integrated.fontSize": 18, - "workbench.activityBar.visible": true, - "workbench.colorTheme": "Default Light Modern", + "workbench.colorTheme": "Visual Studio Dark", "workbench.fontAliasing": "antialiased", "workbench.statusBar.visible": true, "python.linting.enabled": false -} \ No newline at end of file +} From cee3637f798bf5f56b3f8dc9bc8a08bfb685996a Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 11:37:51 -0700 Subject: [PATCH 02/19] Create testfile --- testfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 testfile diff --git a/testfile b/testfile new file mode 100644 index 0000000..e69de29 From 903a37e20058b28827857b7f1316dd78b30b47b6 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 11:39:05 -0700 Subject: [PATCH 03/19] testing --- testfile | 1 + 1 file changed, 1 insertion(+) diff --git a/testfile b/testfile index e69de29..9a2c773 100644 --- a/testfile +++ b/testfile @@ -0,0 +1 @@ +testing \ No newline at end of file From 90c78bd4d88890c3485bc3167ccfde210f9d2079 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 11:47:53 -0700 Subject: [PATCH 04/19] Delete testfile --- testfile | 1 - 1 file changed, 1 deletion(-) delete mode 100644 testfile diff --git a/testfile b/testfile deleted file mode 100644 index 9a2c773..0000000 --- a/testfile +++ /dev/null @@ -1 +0,0 @@ -testing \ No newline at end of file From ceba63bc79468d256dba39d778e21d8796b9c39f Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:03:02 -0700 Subject: [PATCH 05/19] testing my commit --- testfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 testfile diff --git a/testfile b/testfile new file mode 100644 index 0000000..e69de29 From 76256e8d11eeabb9bd96babc979b5d97e95d4bad Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:03:22 -0700 Subject: [PATCH 06/19] testing my commit --- testfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 testfile diff --git a/testfile b/testfile deleted file mode 100644 index e69de29..0000000 From a3d146356882bd0e7ddf0551bf80a85d94788a79 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:06:44 -0700 Subject: [PATCH 07/19] adding tesfile --- testfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 testfile diff --git a/testfile b/testfile new file mode 100644 index 0000000..e69de29 From 3c82c23ca7f75cbc91f86290ab041deae241315b Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:09:23 -0700 Subject: [PATCH 08/19] Update and rename testfile to branch_GitHub_link --- branch_GitHub_link | 1 + testfile | 0 2 files changed, 1 insertion(+) create mode 100644 branch_GitHub_link delete mode 100644 testfile diff --git a/branch_GitHub_link b/branch_GitHub_link new file mode 100644 index 0000000..980cdd2 --- /dev/null +++ b/branch_GitHub_link @@ -0,0 +1 @@ +https://github.com/DonArchila/python-object-oriented-programming-4413110/tree/my_course_work diff --git a/testfile b/testfile deleted file mode 100644 index e69de29..0000000 From 172b64d70371b6314a52c67198b51360ad2d92b5 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:15:22 -0700 Subject: [PATCH 09/19] Update branch_GitHub_link --- branch_GitHub_link | 2 ++ 1 file changed, 2 insertions(+) diff --git a/branch_GitHub_link b/branch_GitHub_link index 980cdd2..0a875b1 100644 --- a/branch_GitHub_link +++ b/branch_GitHub_link @@ -1 +1,3 @@ https://github.com/DonArchila/python-object-oriented-programming-4413110/tree/my_course_work + +this is a fork from original LinkedIn course with my changes and course work From 3ad626ae466fd6160dc58bbb8491cab36b2351ea Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:18:28 -0700 Subject: [PATCH 10/19] Update branch_GitHub_link --- branch_GitHub_link | 2 ++ 1 file changed, 2 insertions(+) diff --git a/branch_GitHub_link b/branch_GitHub_link index 0a875b1..817d9a0 100644 --- a/branch_GitHub_link +++ b/branch_GitHub_link @@ -1,3 +1,5 @@ https://github.com/DonArchila/python-object-oriented-programming-4413110/tree/my_course_work this is a fork from original LinkedIn course with my changes and course work + +testing fetch on VS Code after update on GitHub.com From 85c788077838d72e5a9c1806d3f4b2deecf9e218 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:19:36 -0700 Subject: [PATCH 11/19] removing update made on GitHub.com --- branch_GitHub_link | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/branch_GitHub_link b/branch_GitHub_link index 817d9a0..4824a0b 100644 --- a/branch_GitHub_link +++ b/branch_GitHub_link @@ -1,5 +1,3 @@ https://github.com/DonArchila/python-object-oriented-programming-4413110/tree/my_course_work -this is a fork from original LinkedIn course with my changes and course work - -testing fetch on VS Code after update on GitHub.com +this is a fork from original LinkedIn course with my changes and course work \ No newline at end of file From b1343d40225d9627a4d3a7259372e94a97becfb8 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:23:10 -0700 Subject: [PATCH 12/19] Update branch_GitHub_link --- branch_GitHub_link | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/branch_GitHub_link b/branch_GitHub_link index 4824a0b..fe8316e 100644 --- a/branch_GitHub_link +++ b/branch_GitHub_link @@ -1,3 +1,5 @@ https://github.com/DonArchila/python-object-oriented-programming-4413110/tree/my_course_work -this is a fork from original LinkedIn course with my changes and course work \ No newline at end of file +this is a fork from original LinkedIn course with my changes and course work + +testing again From 4d877a94d634029f2392b3ef5111d0aa27328ed6 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sat, 21 Dec 2024 12:26:55 -0700 Subject: [PATCH 13/19] updating --- branch_GitHub_link | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/branch_GitHub_link b/branch_GitHub_link index fe8316e..4824a0b 100644 --- a/branch_GitHub_link +++ b/branch_GitHub_link @@ -1,5 +1,3 @@ https://github.com/DonArchila/python-object-oriented-programming-4413110/tree/my_course_work -this is a fork from original LinkedIn course with my changes and course work - -testing again +this is a fork from original LinkedIn course with my changes and course work \ No newline at end of file From 96dd5ab590bfbc6e485264dc266a83d23a8af778 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sun, 22 Dec 2024 11:12:12 -0700 Subject: [PATCH 14/19] Add Stock class with initialization and description method --- Start/Ch 1/challenge.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Start/Ch 1/challenge.py b/Start/Ch 1/challenge.py index 050cd6d..31e795b 100644 --- a/Start/Ch 1/challenge.py +++ b/Start/Ch 1/challenge.py @@ -8,9 +8,14 @@ # Company (string) # And a method get_description() which returns a string in the form # of "Ticker: Company -- $Price" - +#%% class Stock: - pass + def __init__(self, ticker, price, company): + self.ticker = ticker + self.price = price + self.company = company + def get_description(self): + return f"{self.ticker}: {self.company} -- ${self.price}" # ~~~~~~~~~ TEST CODE ~~~~~~~~~ msft = Stock("MSFT", 342.0, "Microsoft Corp") @@ -22,3 +27,4 @@ class Stock: print(goog.get_description()) print(meta.get_description()) print(amzn.get_description()) + From 31c6c8a80cd72d75ac62386e1db28fa53b3a6a9b Mon Sep 17 00:00:00 2001 From: DonArchila Date: Sun, 22 Dec 2024 11:12:27 -0700 Subject: [PATCH 15/19] Remove unnecessary blank line in challenge.py --- Start/Ch 1/challenge.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Start/Ch 1/challenge.py b/Start/Ch 1/challenge.py index 31e795b..ab7aa7e 100644 --- a/Start/Ch 1/challenge.py +++ b/Start/Ch 1/challenge.py @@ -27,4 +27,3 @@ def get_description(self): print(goog.get_description()) print(meta.get_description()) print(amzn.get_description()) - From 7fb64121b2e023e9d39f6849f9f17a439f7befcf Mon Sep 17 00:00:00 2001 From: DonArchila Date: Wed, 25 Dec 2024 13:32:45 -0700 Subject: [PATCH 16/19] Refactor Stock and Bond classes to inherit from Asset and implement get_description method --- Start/Ch 1/challenge.py | 4 ++++ Start/Ch 2/challenge.py | 33 +++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Start/Ch 1/challenge.py b/Start/Ch 1/challenge.py index ab7aa7e..e6578a9 100644 --- a/Start/Ch 1/challenge.py +++ b/Start/Ch 1/challenge.py @@ -9,6 +9,8 @@ # And a method get_description() which returns a string in the form # of "Ticker: Company -- $Price" #%% + +from abc import ABC, abstractmethod class Stock: def __init__(self, ticker, price, company): self.ticker = ticker @@ -27,3 +29,5 @@ def get_description(self): print(goog.get_description()) print(meta.get_description()) print(amzn.get_description()) + +# %% diff --git a/Start/Ch 2/challenge.py b/Start/Ch 2/challenge.py index 556fd1f..47af365 100644 --- a/Start/Ch 2/challenge.py +++ b/Start/Ch 2/challenge.py @@ -1,3 +1,6 @@ + +#%% + # Python Object Oriented Programming by Joe Marini course example # Programming challenge: use inheritance and abstract classes @@ -12,14 +15,31 @@ # For stocks: "Ticker: Company -- $Price" # For bonds: "description: duration'yr' : $price : yieldamt%" -class Asset(): - pass +from abc import ABC, abstractmethod +class Asset(ABC): + def __init__(self, price): + self.price = price + @abstractmethod + def get_description(self): + pass + -class Stock(): - pass +class Stock(Asset): + def __init__(self, ticker, price, company): + super().__init__(price) + self.ticker = ticker + self.company = company + def get_description(self): + return f"{self.ticker}: {self.company} -- ${self.price}" -class Bond(): - pass +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 ~~~~~~~~~ @@ -47,3 +67,4 @@ class Bond(): print(us10yr.get_description()) print(us5yr.get_description()) print(us2yr.get_description()) +# %% From aecbf7bcc93fdbcb86111c7a59bf6915ff528fed Mon Sep 17 00:00:00 2001 From: DonArchila Date: Wed, 25 Dec 2024 13:38:04 -0700 Subject: [PATCH 17/19] Add string representation and comparison methods to Stock and Bond classes --- Start/Ch 3/challenge.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Start/Ch 3/challenge.py b/Start/Ch 3/challenge.py index 679db2b..7995f90 100644 --- a/Start/Ch 3/challenge.py +++ b/Start/Ch 3/challenge.py @@ -5,6 +5,7 @@ # Stocks should sort from low to high on price # Bonds should sort from low to high on yield +#%% from abc import ABC, abstractmethod @@ -22,7 +23,11 @@ def __init__(self, ticker, price, company): super().__init__(price) self.company = company self.ticker = ticker + def __str__(self): + return f"{self.ticker}: {self.company} -- ${self.price}" + def __lt__(self, other): + return self.price < other.price class Bond(Asset): def __init__(self, price, description, duration, yieldamt): @@ -30,7 +35,11 @@ def __init__(self, price, description, duration, yieldamt): self.description = description 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 = [ From e16e2721b5e252171fc5d4c28bdf2d84149aa828 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Wed, 25 Dec 2024 14:39:22 -0700 Subject: [PATCH 18/19] Implement Asset, Stock, and Bond classes with string representation and comparison methods --- Start/Ch 4/challenge.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Start/Ch 4/challenge.py b/Start/Ch 4/challenge.py index f7634d0..9c42751 100644 --- a/Start/Ch 4/challenge.py +++ b/Start/Ch 4/challenge.py @@ -5,17 +5,40 @@ # The subclasses are required to override the magic method # that makes them sortable +#%% + +from dataclasses import dataclass + +@dataclass class Asset(): - pass - + price: float + def __str__(self): + pass + def __lt__(self, other): + pass + +@dataclass class Stock(Asset): - pass + ticker: str + company: str + def __str__(self): + return f"{self.ticker}: {self.company} -- ${self.price}" + def __lt__(self, other): + return self.price < other.price +@dataclass class Bond(Asset): - pass + description: str + duration: int + yieldamt: float + 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 = [ Stock("MSFT", 342.0, "Microsoft Corp"), @@ -44,3 +67,5 @@ class Bond(Asset): print("-----------") for bond in bonds: print(bond) + +# %% From 2e817f5600d7c45af0be8a122eb0a149905c9d09 Mon Sep 17 00:00:00 2001 From: DonArchila Date: Wed, 25 Dec 2024 15:13:49 -0700 Subject: [PATCH 19/19] Refactor Asset class to inherit from ABC and define abstract methods for string representation --- Start/Ch 4/challenge.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Start/Ch 4/challenge.py b/Start/Ch 4/challenge.py index 9c42751..b6e8136 100644 --- a/Start/Ch 4/challenge.py +++ b/Start/Ch 4/challenge.py @@ -8,13 +8,16 @@ #%% from dataclasses import dataclass +from abc import ABC, abstractmethod @dataclass -class Asset(): +class Asset(ABC): price: float - def __str__(self): - pass + # @abstractmethod + # def __str__(self): + # pass + @abstractmethod def __lt__(self, other): pass @@ -23,8 +26,8 @@ class Stock(Asset): ticker: str company: str - def __str__(self): - return f"{self.ticker}: {self.company} -- ${self.price}" + # def __str__(self): + # return f"{self.ticker}: {self.company} -- ${self.price}" def __lt__(self, other): return self.price < other.price @@ -34,8 +37,8 @@ class Bond(Asset): duration: int yieldamt: float - def __str__(self): - return f"{self.description}: {self.duration}yr : ${self.price} : {self.yieldamt}%" + # def __str__(self): + # return f"{self.description}: {self.duration}yr : ${self.price} : {self.yieldamt}%" def __lt__(self, other): return self.yieldamt < other.yieldamt