Advertisement
Guest User

newfile.py

a guest
Jul 29th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. prices = [9, 11, 8, 5, 7, 10]
  2.  
  3. def buy_and_sell(stock_prices):  
  4.     largest_profit = 0  
  5.     for i in range(len(stock_prices)):    
  6.         for k in stock_prices[i:]:    
  7.             if k - stock_prices[i] > largest_profit:
  8.                 largest_profit = k - stock_prices[i]  
  9.     return largest_profit
  10.  
  11. print(buy_and_sell(prices))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement