[SOLVED] maxprofit.py

25.00 $

Programming resource
Digital learning resource
Category: Tag:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (2 votes)

You should save the solution to this problem in a file called maxprofit.py if you wish to use the tester program. write a function called maxprofit that accepts a single list argument as input (referred to as mylist in this description). The function should determine the maximum profit that can be made by ‘buying’ a stock at one index in mylist and ‘selling’ it at a later index. In this case, you can calculate the profit of buying at index x and selling at index y as mylist[y] – mylist[x]. Note that the selling index must come after the buying index. Your function must return a list with the following 3 pieces of information: the buy index, the sell index, and the maximum profit. You may assume

that at least one combination of buy/sell prices that exist produce a positive profit. You can also assume that there will be only one maximum combination (i.e., no ties exist).

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.