logo CodeStepByStep logo

Stock

Language/Type: Python classes
Related Links:

Write a class named Stock where each object represents purchases of shares of stock. Your class should contain the following members:

member name type description
Stock(symbol) constructor constructs a new stock representing the given symbol such as "YHOO"
s.symbol property stock symbol as passed to the constructor, as a string (read-only)
s.total_cost property total cost of all stock shares purchased, as a real number (read-only)
s.total_shares property total number of shares purchased of this stock (initially 0) (read-only)
s.profit(current_price) method returns the total amount of profit earned on the shares of this stock, given today's current price per share (accessor)
s.purchase(shares, price) method records the purchase of the given number of shares of this stock at the given price per share (mutator)
Class: Write a complete Python class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.