Skip to content

Add execute function #3

@rbetzler

Description

@rbetzler

In general, when we write a class, we want to write one execute function, which will run all the other functions in our class, in the order we want, in the way we want.

For example, when we write our StockAnalysis class, we want one function (named execute) that will call the other functions that get a list of stocks, get the data for each stock, run the calculations, etc.

Here's a simple example:

class StockAnalysis:
  def get_stocks(self):
    return ['x']

  def calculate_performance(self, stock):
    performance = 'company {stock} lost $10'.format(stock=stock)
    return performance

  def execute(self):
    stocks = self.get_stocks()
    for stock in stocks:
      performance = self.calculate_performance(stock)
    print(performance)

if __name__ == '__main__':
  StockAnalysis().execute()

Task:

  • Cleanup main.py so that it has the above structure
  • Feel free to add placeholders for functions we have not yet implemented
    • For example, we don't have a performance calculator yet; create a place holder that doesn't do anything

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions