Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
DonArchila wants to merge19 commits intoLinkedInLearning:main
base:main
Choose a base branch
Loading
fromDonArchila:my_course_work
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
c3fb143
Update settings.json
DonArchilaDec 21, 2024
cee3637
Create testfile
DonArchilaDec 21, 2024
903a37e
testing
DonArchilaDec 21, 2024
90c78bd
Delete testfile
DonArchilaDec 21, 2024
ceba63b
testing my commit
DonArchilaDec 21, 2024
76256e8
testing my commit
DonArchilaDec 21, 2024
a3d1463
adding tesfile
DonArchilaDec 21, 2024
3c82c23
Update and rename testfile to branch_GitHub_link
DonArchilaDec 21, 2024
172b64d
Update branch_GitHub_link
DonArchilaDec 21, 2024
3ad626a
Update branch_GitHub_link
DonArchilaDec 21, 2024
85c7880
removing update made on GitHub.com
DonArchilaDec 21, 2024
b1343d4
Update branch_GitHub_link
DonArchilaDec 21, 2024
4d877a9
updating
DonArchilaDec 21, 2024
96dd5ab
Add Stock class with initialization and description method
DonArchilaDec 22, 2024
31c6c8a
Remove unnecessary blank line in challenge.py
DonArchilaDec 22, 2024
7fb6412
Refactor Stock and Bond classes to inherit from Asset and implement g…
DonArchilaDec 25, 2024
aecbf7b
Add string representation and comparison methods to Stock and Bond cl…
DonArchilaDec 25, 2024
e16e272
Implement Asset, Stock, and Bond classes with string representation a…
DonArchilaDec 25, 2024
2e817f5
Refactor Asset class to inherit from ABC and define abstract methods …
DonArchilaDec 25, 2024
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
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionStart/Ch 1/challenge.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsStart/Ch 2/challenge.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand Up@@ -47,3 +67,4 @@ class Bond():
print(us10yr.get_description())
print(us5yr.get_description())
print(us2yr.get_description())
# %%
9 changes: 9 additions & 0 deletionsStart/Ch 3/challenge.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsStart/Ch 4/challenge.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand Up@@ -44,3 +70,5 @@ class Bond(Asset):
print("-----------")
for bond in bonds:
print(bond)

# %%
3 changes: 3 additions & 0 deletionsbranch_GitHub_link
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp