Skip to content

My_course_work #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
11 changes: 10 additions & 1 deletion Start/Ch 1/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
# Company (string)
# And a method get_description() which returns a string in the form
# of "Ticker: Company -- $Price"
#%%

from abc import ABC, abstractmethod
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")
Expand All @@ -22,3 +29,5 @@ class Stock:
print(goog.get_description())
print(meta.get_description())
print(amzn.get_description())

# %%
33 changes: 27 additions & 6 deletions Start/Ch 2/challenge.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

#%%

# Python Object Oriented Programming by Joe Marini course example
# Programming challenge: use inheritance and abstract classes

Expand All @@ -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 ~~~~~~~~~
Expand Down Expand Up @@ -47,3 +67,4 @@ class Bond():
print(us10yr.get_description())
print(us5yr.get_description())
print(us2yr.get_description())
# %%
9 changes: 9 additions & 0 deletions Start/Ch 3/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -22,15 +23,23 @@ 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):
super().__init__(price)
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 = [
Expand Down
38 changes: 33 additions & 5 deletions Start/Ch 4/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,43 @@
# The subclasses are required to override the magic method
# that makes them sortable

class Asset():
pass

#%%

from dataclasses import dataclass
from abc import ABC, abstractmethod

@dataclass
class Asset(ABC):
price: float

# @abstractmethod
# def __str__(self):
# pass
@abstractmethod
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"),
Expand Down Expand Up @@ -44,3 +70,5 @@ class Bond(Asset):
print("-----------")
for bond in bonds:
print(bond)

# %%
3 changes: 3 additions & 0 deletions branch_GitHub_link
Original file line number Diff line number Diff line change
@@ -0,0 +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