Guest User

newfile.py

a guest
Jul 29th, 2020
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
RAW Paste Data