I'm getting an unbound local error and I don't know how to fix it

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Here is the link to the problem I’m dealing with: https://www.codecademy.com/paths/computer-science/tracks/cspath-cumulative-tourism/modules/cspath-boredless-tourist/projects/the-boredless-tourist

I keep getting an “UnboundLocalError” and I don’t know how to fix the code

def find_attractions(destination, interests):
destination_index = get_destination_index(destination)
attractions_in_city = attractions[destination_index]
attractions_with_interest =

for attractions in attractions_in_city:
possible_attraction = attraction
attraction_tags = attraction[1]

for intrest in intrests:
  if interest in attraction_tags:
    attractions_with_interest.append(possible_attraction)

return attractions_with_interest

la_arts = find_attractions(“Los Angeles, USA”, [‘art’])
print(la_arts)

plz help

Check spelling before looking further.

1 Like

The line that says “attractions_in_city = attractions[destination_index]” is where it says the unbound local error is coming up

And could you tell how to put the entire code in that grey box. I don’t know why only part of it is showing up.

Select all the code and click the </> tool in the toolbar.

Be sure to check for spelling errors before drawing any conclusions. Fix those, then test again. It may give new errors, or none.

Alright figured it out. Thank you so much

1 Like

Please help:

I am getting two errors:
one at “la_arts = find_attractions(‘Los Angeles, USA’, [‘art’])” and another at " attractions_in_city = attractions[destination_index]"
UnboundLocalError

def find_attractions(destination, interests):
  destination_index = get_destination_index(destination)
  attractions_in_city = attractions[destination_index]
  attractions_with_interest =[]
  
  for attractions in attractions_in_city:
    possible_attraction = attraction
    attraction_tags = attraction[1]
    
    for interest in interests:
      if interest in attraction_tags:
        attractions_with_interest.append(possible_attraction)
  return attractions_with_interest
la_arts = find_attractions('Los Angeles, USA', ['art'])

Did you mean, attraction in attractions_in_city

yes, I really meant that. Thank you for finding it so quick.

1 Like