MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / Stock

Class Stock

Solutions/9_2/stock.py:5–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3from structly.structure import Structure
4
5class Stock(Structure):
6 name = String()
7 shares = PositiveInteger()
8 price = PositiveFloat()
9
10 @property
11 def cost(self):
12 return self.shares * self.price
13
14 def sell(self, nshares: PositiveInteger):
15 self.shares -= nshares
16
17if __name__ == '__main__':
18 from structly.reader import read_csv_as_instances

Callers

nothing calls this directly

Calls 3

StringClass · 0.50
PositiveIntegerClass · 0.50
PositiveFloatClass · 0.50

Tested by

no test coverage detected