Question: First, write a function called fin_plan that takes a list of 2 or more prices, and that uses one or more loops to find the

First, write a function called fin_plan that takes a list of 2 or more prices, and that uses one or more loops to find the best days on which to buy and sell the stock whose prices are given in the list of prices. The buy and sell days that you determine should maximize the profit earned, but the sell day must be greater than the buy day. The function should return a list containing three integers:

the buy day

the sell day

the resulting profit

For example:

>>> fin_plan([40, 10, 20, 35, 25]) [1, 3, 25] 

In this case, the function returns a list that indicates that the best investment plan is to buy on day 1 and sell on day 3, which gives a profit of $25. Heres another example:

>>> print(fin_plan([5, 10, 45, 35, 3])) [0, 2, 40]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!