The Borederless Tourist - 'attraction' not defined error

Hi everyone,
I’m receiving an error that ‘global name ‘attraction’ is not defined’ when I run my code, but it seems that I’ve built it out the same way that the guide and several other people who have completed the project did. Any ideas why it’s not picking that up?

destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA", "Sao Paulo, Brazil", "Cairo, Egypt"]

test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]

def get_destination_index(destination):

  destination_index = destinations.index(destination)

  return destination_index

def get_traveler_location(traveler):

  traveler_destination = traveler[1]

  traveler_destination_index = get_destination_index(traveler_destination)

  return traveler_destination_index

test_destination_index = get_traveler_location(test_traveler)

attractions = []

for destination in destinations:


def add_attraction(destination, attraction):


    destination_index = get_destination_index(destination)

    attractions_for_destinaton = attractions[destination_index].append(attraction)


  except ValueError:


add_attraction('Los Angeles, USA', ['Venice Beach', ['beach']])

add_attraction("Paris, France", ["the Louvre", ["art", "museum"]])

add_attraction("Paris, France", ["Arc de Triomphe", ["historical site", "monument"]])

add_attraction("Shanghai, China", ["Yu Garden", ["garden", "historcical site"]])

add_attraction("Shanghai, China", ["Yuz Museum", ["art", "museum"]])

add_attraction("Shanghai, China", ["Oriental Pearl Tower", ["skyscraper", "viewing deck"]])

add_attraction("Los Angeles, USA", ["LACMA", ["art", "museum"]])

add_attraction("Sao Paulo, Brazil", ["Sao Paulo Zoo", ["zoo"]])

add_attraction("Sao Paulo, Brazil", ["Patio do Colegio", ["historical site"]])

add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]])

add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]])

def find_attractions(destination, interests):

  destination_index = get_destination_index(destination)

  attractions_in_city = attractions[destination_index]

  attractions_with_interest = []

  for possible_attraction in attractions_in_city:

    possible_attraction = attraction

    attraction_tags = attractions[1]

    for interest in interests:

      if interest in attraction_tags:



  return attractions_with_interest


print(find_attractions('Los Angeles, USA', ['art']))

This is the error:


I figured it out :slight_smile:

in my loop within the ‘find_attractions’ function:

for possible_attraction in attractions_in_city:

    possible_attraction = attraction

    attraction_tags = attractions[1]

I used the variable name ‘possible_attraction’ as the temp variable for the loop then tried to associate it to ‘attraction’ as the looping variable. once I replaced it with the correct element names it worked.

Solution code:

for attraction in attractions_in_city:

    possible_attraction = attraction

    attraction_tags = possible_attraction[1]
1 Like