An instance of a stock holding consisting of name, shares, and price.
| 3 | from typedproperty import String, Integer, Float |
| 4 | |
| 5 | class Stock: |
| 6 | ''' |
| 7 | An instance of a stock holding consisting of name, shares, and price. |
| 8 | ''' |
| 9 | name = String('name') |
| 10 | shares = Integer('shares') |
| 11 | price = Float('price') |
| 12 | |
| 13 | def __init__(self,name, shares, price): |
| 14 | self.name = name |
| 15 | self.shares = shares |
| 16 | self.price = price |
| 17 | |
| 18 | def __repr__(self): |
| 19 | return f'Stock({self.name!r}, {self.shares!r}, {self.price!r})' |
| 20 | |
| 21 | @property |
| 22 | def cost(self): |
| 23 | ''' |
| 24 | Return the cost as shares*price |
| 25 | ''' |
| 26 | return self.shares * self.price |
| 27 | |
| 28 | def sell(self, nshares): |
| 29 | ''' |
| 30 | Sell a number of shares and return the remaining number. |
| 31 | ''' |
| 32 | self.shares -= nshares |
nothing calls this directly
no outgoing calls
no test coverage detected