Answer to Question #265569 in Python for GANESH

Question #265569

You are given a list of prices, where price [ i ] is the price of a given stock on the i th day


Write a program to print the maximum profit by choosing a single day to buy a stock and choosing a different day in the future to sell that stock


If there is no profit that can be achived return 0


Input:

The input is a single line containing space - separated integers


output:

The output should be a an integer


sample Input1:

7 1 5 3 6 4


sampleoutput1:

5


sampleinput2:

1 11 13 21 19


sample output2:

20


1
Expert's answer
2021-11-13T12:41:12-0500


#Price = [7, 1, 5, 3, 6, 4]
P = input("Enter Price followed by SPACE: ")
P = str(P).split(" ")
Price=[]
for r in range(0,len(P)):
    Price.append(int(P[r]))
Profit = max(Price)-min(Price)


print(Profit)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS