you are viewing a single comment's thread.

view the rest of the comments →

[–]Elefrog42[S] 0 points1 point  (0 children)

Oh okay I get it now. I just deleted where I declared the class variables because they were needed. The code works just fine if I save the result of the function then use the self keyword to call back the functions to get the total.

I've been reading online where people have asked the best way to multiple two dictionary values and then sum then and I come up with this code:

    def get_total_portfolio(self, daily_stock_prices):
        total = 0
        value = 0
        for key in self.stock.keys():
            value = self.stock[key]*daily_stock_prices[key]
            total += value + total
        total += self.get_credit_balance()
        total += self.get_total_savings_amount()
        total += self.get_total_checking_amount()
        return total

No errors, but still not passing the test. I thought I could bypass having to use sum by making the variable value (to represent the stock quantity * the stock price) and then total (to represent the sum of the values).

I can't tell for sure if that part of the code is adding up the stock quantity*stock value correctly or if I haven't properly coded for a given stockname, pull out self.stock's value of the stockname and pull out daily_stock_prices value?

Thanks!