MCPcopy Index your code
hub / github.com/dabeaz-course/practical-python / Stock

Class Stock

Solutions/4_10/stock.py:3–25  ·  view source on GitHub ↗

An instance of a stock holding consisting of name, shares, and price.

Source from the content-addressed store, hash-verified

1# stock.py
2
3class Stock:
4 '''
5 An instance of a stock holding consisting of name, shares, and price.
6 '''
7 def __init__(self, name, shares, price):
8 self.name = name
9 self.shares = shares
10 self.price = price
11
12 def __repr__(self):
13 return f'Stock({self.name!r}, {self.shares!r}, {self.price!r})'
14
15 def cost(self):
16 '''
17 Return the cost as shares*price
18 '''
19 return self.shares * self.price
20
21 def sell(self, nshares):
22 '''
23 Sell a number of shares
24 '''
25 self.shares -= nshares
26

Callers 1

read_portfolioFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected