Files
practical-python/Solutions/4_4/stock.py
2020-05-27 17:03:35 -05:00

24 lines
495 B
Python

# stock.py
class Stock(object):
'''
An instance of a stock holding consisting of name, shares, and price.
'''
def __init__(self, name, shares, price):
self.name = name
self.shares = shares
self.price = price
def cost(self):
'''
Return the cost as shares*price
'''
return self.shares * self.price
def sell(self, nshares):
'''
Sell a number of shares
'''
self.shares -= nshares