The Boredless Tourist

Hi there, I am working on the Boredless Tourist and I am dealing with a bug that I haven’t been able to identify. my code is printing an empty list instead of [[‘LACMA’, [‘art’, ‘museum’]]], and I don’t really understand where the mistake is, can please someone help me? This is my code:

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

for attraction 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’])

print(la_arts)

Apart from the fact that unformatted code in incredibly hard to decipher, can you bring us up to speed on the value of attraction[1]?

Aside

Please learn how to post formatted code, else expect a weak response to your questions.

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

  for attraction 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"])

print(la_arts)



# Attractions added.
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", "historical 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("São Paulo, Brazil", ["São Paulo Zoo", ["zoo"]])
add_attraction("São Paulo, Brazil", ["Pátio do Colégio", ["historical site"]])
add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]])
add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]])

Okay, I figured out how to post formatted code. Additionally, based on the data that I am providing now, attraction[1] indicates the attraction tags for each given attraction.

1 Like

Not sure what purpose this serves. Please explain.

Also, please post a link to this exercise/project so we can get a closer look.

https://www.codecademy.com/journeys/computer-science/paths/cscj-22-intro-to-programming/tracks/cscj-22-project-the-boredless-tourist/modules/cscj-22-project-git-the-boredless-tourist/projects/the-boredless-tourist

Please let me know if this link works properly.

possible_attraction is then appended to attractions_with_interest in the nested for loop.

By the way, it’s pretty cool how code can be shared here, it’s my first trying it. Thank you for helping me get through it.

2 Likes

Should it be,

possible_attraction[0]

?

The thing is that

possible_attraction[0]

is to be written in step 49 since this is to show the mentioned tag/tags and avoid the ones that you don’t want to see. So it should work without [0].

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

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

# Loop to create 5 empty lists.
attractions = []
for attraction in destinations:
  attractions.append([])


# Functions
def get_destination_index(destination):
  destination_index = destinations.index(destination)
  return destination_index

def get_traveler_location(traveler):
  travel_destination = traveler[1]
  traveler_destination_index = get_destination_index(travel_destination)
  return traveler_destination_index

def add_attraction(destination, attraction):
  destination_index = get_destination_index(destination)
  attractions_for_destination = attractions[destination_index]
  attractions_for_destination.append(attraction)
  return attractions_for_destination

# We need to match travelers'interests with the possible locations in a city, which will be accomplished by using the function find_attractions.

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

  for attraction 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

print(attractions)
la_arts = find_attractions("Los Angeles, USA", ["art"])

print(la_arts)



# Attractions added.
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", "historical 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("São Paulo, Brazil", ["São Paulo Zoo", ["zoo"]])
add_attraction("São Paulo, Brazil", ["Pátio do Colégio", ["historical site"]])
add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]])
add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]])

This is the code that I have so far.

I’m getting, `[‘LACMA’]. No problems in your code are jumping out, but I’m not at my best today so could be missing something. Sorry I can’t be of more help.

One member who has been extremely helpful with this project in the past was @appylpye. Search for his posts and see what insights can be gleaned from there.

1 Like

I really thank you for your effort. I finaly could figure it out. I was providing all the attraction data after the call of the function, which will not work because the function was not receiving any data, so the data should come before the function. :melting_face:

3 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.