Question: 1. Write a function called min_day that takes a list of 1 or more prices and computes and returns the day (i.e., the index) of

1. Write a function called min_day that takes a list of 1 or more prices and computes and returns the day (i.e., the index) of the minimum price. Dont forget that you cannot use the built-in sum, min, or max functions.

Here are two examples:

>>> min_day([20, 10, 18]) 1 >>> print(min_day([15, 18, 12, 22, 17])) 2

2. Begin by writing a function called any_above that takes a list of 1 or more prices and an integer threshold, and uses a loop to determine if there are any prices above that threshold. The function should return True if there are any prices above the threshold, and False otherwise. For example:

>>> any_above([10, 20, 15], 18) True >>> print(any_above([10, 20, 15], 25)) False 

Important: Make sure that you return either the boolean literal True or the boolean literal False. Do not include quotes around these values.

3.

First, write a function called find_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:

>>> find_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(find_plan([5, 10, 45, 35, 3])) [0, 2, 40] 

Hint: In implementing this function, you may find it helpful to adapt the example diff function that we covered in lecture.

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!