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

Class Stock

Solutions/4_3/validate.py:62–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 return x + y
61
62 class Stock:
63 name = NonEmptyString()
64 shares = PositiveInteger()
65 price = PositiveFloat()
66 def __init__(self, name, shares, price):
67 self.name = name
68 self.shares = shares
69 self.price = price
70
71 def __repr__(self):
72 return f'Stock({self.name!r}, {self.shares!r}, {self.price!r})'
73
74 @property
75 def cost(self):
76 return self.shares * self.price
77
78 def sell(self, nshares):
79 self.shares -= nshares
80
81
82

Callers

nothing calls this directly

Calls 3

NonEmptyStringClass · 0.70
PositiveIntegerClass · 0.70
PositiveFloatClass · 0.70

Tested by

no test coverage detected