File tree Expand file tree Collapse file tree 4 files changed +26
-5
lines changed Expand file tree Collapse file tree 4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 11# Python Object Oriented Programming by Joe Marini course example
22# Programming challenge: define a class to represent a stock symbol
33
4+ # Challenge: create a class to represent stock information.
5+ # Your class should have properties for:
6+ # Ticker (string)
7+ # Price (float)
8+ # Company (string)
9+ # And a method get_description() which returns a string in the form
10+ # of "Ticker: Company -- $Price"
411
512class Stock :
613 pass
Original file line number Diff line number Diff line change 11# Python Object Oriented Programming by Joe Marini course example
22# Programming challenge: use inheritance and abstract classes
33
4- from abc import ABC , abstractmethod
4+ # Challenge: create a class structure to represent stocks and bonds
5+ # Requirements:
6+ # -- Both stocks and bonds have a price
7+ # -- Stocks have a company name and ticker
8+ # -- Bonds have a description, duration, and yield
9+ # -- You should not be able to instantiate the base class
10+ # -- Subclasses are required to override get_description()
11+ # -- get_description returns formats for stocks and bonds
12+ # For stocks: "Ticker: Company -- $Price"
13+ # For bonds: "description: duration'yr' : $price : yieldamt%"
514
615class Asset ():
716 pass
Original file line number Diff line number Diff line change 11# Python Object Oriented Programming by Joe Marini course example
22# Programming challenge: add methods for comparison and equality
33
4+ # Challenge: use a magic method to make stocks and bonds sortable
5+ # Stocks should sort from low to high on price
6+ # Bonds should sort from low to high on yield
7+
48from abc import ABC , abstractmethod
59
610
Original file line number Diff line number Diff line change 11# Python Object Oriented Programming by Joe Marini course example
22# Programming challenge: implement a dataclass
33
4- from dataclasses import dataclass
5- from abc import ABC , abstractmethod
4+ # Challenge: convert your classes to dataclasses
5+ # The subclasses are required to override the magic method
6+ # that makes them sortable
67
78class Asset ():
89 pass
910
1011
1112class Stock (Asset ):
12- pass
13+ pass
1314
1415
1516class Bond (Asset ):
16- pass
17+ pass
1718
1819# ~~~~~~~~~ TEST CODE ~~~~~~~~~
1920stocks = [
You can’t perform that action at this time.
0 commit comments