怎么都不知道错哪了?在线求解

不知道哪错了啊,刚学啥都不懂,。

img

img


感激不尽,。!?感激不尽啊,。?!

试试:

prices = eval(input())
buy = benifit = 0
stock = False
for i in range(len(prices)-1):
    if not stock and prices[i+1]>prices[i]:        
        buy = prices[i]
        stock = True
    if stock and prices[i+1]<prices[i]:        
        benifit += (prices[i]-buy)
        stock = False
if stock:
    benifit += (prices[i+1]-buy)

print(benifit)