0

I'm having some serious trouble getting the index function to iterate through each of the user's stocks to obtain the current market price. It correctly outputs a list of the user's stocks along with the sum of shares owned of each stock, but I can't get it to output the current price of each stock (and also the total current value of each stock). Any help would be very much appreciated as always.

Link to the code and the html page: https://gist.github.com/choaimeloo/e21a4eb13790becfa3a43a2ba6a91220

0

Your index () function returns during the first iteration of your for loop. At that point, you have only looked up the price for the first symbol.

You should collect the price and value for all symbols in the portfolio before the function returns.

  • You've helped me out before, Peter -- thanks for stepping up again. What I don't understand is why the code iterates through the symbol and the sum of shares for each stock but not the current price (via the lookup function). Also, your suggestion makes sense to me, but I don't know how to implement it. Do I create an empty list and append each value to it and then somehow return those values? – ChoLoo Nov 5 '18 at 9:05
  • Yes. Start with an empty list. And for each symbol in your portfolio add 1 dict to the list which contains all fields you will need for that row in your html-table. – Peter Pesch Nov 5 '18 at 10:53
  • So I've really tried doing what you suggested but still cannot get the current prices and total current values to output. Those fields continue to render blank. What am I missing? Here's a link to the updated code: gist.github.com/choaimeloo/4bbc6bd08e2a76fbd80833defc661731. – ChoLoo Nov 5 '18 at 13:42
  • You didn't add a dict per row to your list, you only added one value (the price) per row. For each row, you should add a dict (or some other data structure) which should (probably) contain the symbol, name, sum, price and stock_value. Your html-file should contain some for-endfor construction like the html-file from the source code for this lesson (week 8, which is the week containing lecture 10, pset 7, src10, etcetera). – Peter Pesch Nov 5 '18 at 17:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .