Stocks change values throughout the day. Assume you have a list that consists of
ID: 3753853 • Letter: S
Question
Stocks change values throughout the day. Assume you have a list that consists of the starting stock price, then a list of the gains and losses during the day. For example, stocki startingPrice, [ehangei,change ,....changen 10,[1.-5,2,-1.45] 10 + 1-.5+ 2-1.45 = 11.05 At the end of the day, the stock was $11.05. Complete the function that calculates the ending value of the stock prices. 1 # Input Parameter: a list x, containing the starting stock price and fluctuations throughout the day 2 # Return Value: the final stock price 3 def finalStockPrice(x) #T000: implement this function 6 stock! [10, [1,-.5.2,-1.45)) 8 stock3 -[400, [10,-9,9,9,-20,24, -22,100, -24,-23] 0 stocks [stock1, stock2, stock3] 11 for i in stocks: 12 print(finalStockPrice(i)) 11.05 2.15 454Explanation / Answer
def finalStockPrice(x): total = x[0] for change in x[1]: total += change return total stock1 = [10, [1, -.5, 2, -1.45]] stock2 = [2, [.4, -.2, .1, .05, -.23, .03]] stock3 = [400, [10, -9, 9, 9, -20, 24, -22, 100, -24, -23]] stocks = [stock1, stock2, stock3] for i in stocks: print(finalStockPrice(i))