File tree 4 files changed +26
-5
lines changed
4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Python Object Oriented Programming by Joe Marini course example
2
2
# Programming challenge: define a class to represent a stock symbol
3
3
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"
4
11
5
12
class Stock :
6
13
pass
Original file line number Diff line number Diff line change 1
1
# Python Object Oriented Programming by Joe Marini course example
2
2
# Programming challenge: use inheritance and abstract classes
3
3
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%"
5
14
6
15
class Asset ():
7
16
pass
Original file line number Diff line number Diff line change 1
1
# Python Object Oriented Programming by Joe Marini course example
2
2
# Programming challenge: add methods for comparison and equality
3
3
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
+
4
8
from abc import ABC , abstractmethod
5
9
6
10
Original file line number Diff line number Diff line change 1
1
# Python Object Oriented Programming by Joe Marini course example
2
2
# Programming challenge: implement a dataclass
3
3
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
6
7
7
8
class Asset ():
8
9
pass
9
10
10
11
11
12
class Stock (Asset ):
12
- pass
13
+ pass
13
14
14
15
15
16
class Bond (Asset ):
16
- pass
17
+ pass
17
18
18
19
# ~~~~~~~~~ TEST CODE ~~~~~~~~~
19
20
stocks = [
You can’t perform that action at this time.
0 commit comments