Reinforcement Learning 'Gert last N 5 minutes bars' returns outside function

In RL Part II under 'Get last N 5 minutes bars', I get SyntaxError: 'return' outside function.

This is saying as I see it that the standard indentation of 4 is violated. But it is not because I have gone through the code and verified each line. I have attached the code as it is in RL Part II under 'Get last N 5 minutes bars'. I do not see the error, or any information on how to correct it. Please advise,

William

'Get last N 5 minutes bars'
def get_last_N_5m_bars(bars5m, curr_time, lkbk):
# This function gets the timebars for the 5m resolution based on the lookback we've specified.

# Width of the data, arbitrarily chosen
    wdw5m = 9
   
# # creating the time bars based on the lookback
# Reduce the size of the data
    curtail_data = bars5m[curr_time-timedelta(wdw5m):curr_time]
   
# Create candlestick based on lookback
    last5m = curtail_data.iloc[-lkbk:]
   
# Making sure that window lengths agree with lookback
try:
    assert(len(last5m) == lkbk)

except Exception as e:
    print('****Window length too short****')
   
    return last5m
 

Hello William, 

The try-except block is not indented correctly and is outside of the function get_last_N_5m_bars(). You should indent the try statement to be at the same level as the previous line, which is the last5m variable declaration.



This would resolve the error SyntaxError: 'return' outside function.



Hope this helps!