Updating query based on user input

Hi , everyone as you can tell I have to update this complicated query based on my user input but i get an error “LIST OUT OF RANGE” I need your help please

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online