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

Class Stock

Solutions/4_4/stock.py:3–22  ·  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 cost(self):
13 '''
14 Return the cost as shares*price
15 '''
16 return self.shares * self.price
17
18 def sell(self, nshares):
19 '''
20 Sell a number of shares
21 '''
22 self.shares -= nshares
23

Callers 1

read_portfolioFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected