Boredless Tourist

So I am about done with the code, but have no idea what adding a string to another does not work in a for loop. The entire code:

destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA", "São 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)
  except NameError:
  attractions_for_destination = attractions[get_destination_index(destination)]

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("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"]])

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[0]
    attraction_tags = attraction[1]
    for interest in interests:
      if interest in attraction_tags:
  return attractions_with_interest

def get_attractions_for_traveler(traveler):
  traveler_destination = traveler[1]
  traveler_interests = traveler[2]
  traveler_attractions = find_attractions(traveler_destination, traveler_interests)
  interest_string = "Hi " + traveler[0] + ", we think you'll like these places around " + traveler_destination + ": "
  for attraction in traveler_attractions:
    interest_string + attraction
  return interest_string

smills_france = get_attractions_for_traveler(["Dereck Smill", "Paris, France", ["monument"]])


The line of code near the end of the last function:

interest_string + attraction

does not add attraction to the string. However if before it I put


it does print the correct attraction. I have tried using


but no dice. It feels like I am missing something very basic.

What’s different about what you do on that line compared to two lines above?

I wasn’t assigning the change to interest_string! I knew it was something basic! Thank you, got it to work.

1 Like

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