Boredless Tourist

Hi I have completed this project but at the end, I am getting error: TypeError: must be str, not list

My script.py file is here:
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

attractions =
for destination in destinations:
attractions.append()

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

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”]])

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

def get_attractions_for_traveler(traveler):
traveler_destination = traveler[1]
traveler_interests = traveler[2]
traveler_attractions = find_attractions(traveler_destination, traveler_interests)

interests_string = "Hi " + traveler[0] + ", we think you’ll like these places around " + traveler_destination + ": "
for i in range(len(traveler_attractions)):
if traveler_attractions[-1] == traveler_attractions[i]:
interests_string += "the " + traveler_attractions[i] + ". "
else:
interests_string += "the " + traveler_attractions[i] + ", "
return interests_string

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

print(smills_france)

Could you please help me to solve it!
Thank you.

I’d be happy to try, if you’ll re-post your code with its original formatting intact. See How do I format code in my posts?
It would also be very helpful if you post the entire actual error message that shows the line of code where the error was thrown.

2 Likes
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

attractions = 
for destination in destinations:
attractions.append()

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

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”]])

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

def get_attractions_for_traveler(traveler):
traveler_destination = traveler[1]
traveler_interests = traveler[2]
traveler_attractions = find_attractions(traveler_destination, traveler_interests)

interests_string = "Hi " + traveler[0] + ", we think you’ll like these places around " + traveler_destination + ": "
for i in range(len(traveler_attractions)):
if traveler_attractions[-1] == traveler_attractions[i]:
interests_string += "the " + traveler_attractions[i] + ". "
else:
interests_string += "the " + traveler_attractions[i] + ", "
return interests_string

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

print(smills_france)

Here I am posing link for my project code. I really need to know where I need to correct my code.

https://www.codecademy.com/workspaces/64d293a5e09f96dcc878bbf7

Thank you.

From your code:

def get_attractions_for_traveler(traveler):
  traveler_destination = traveler[1]
  traveler_interests = traveler[2]
  traveler_attractions = find_attractions(traveler_destination, traveler_interests)

  interests_string = "Hi " + traveler[0] + ", we think you'll like these places around " + traveler_destination + ": "
  for i in range(len(traveler_attractions)):
    print(traveler_attractions[i]) #debug print
    if traveler_attractions[-1] == traveler_attractions[i]:
      interests_string += "the " + traveler_attractions[i] + ". "
    else: 
      interests_string += "the " + traveler_attractions[i] + ", "
  return interests_string

The error is thrown when this function is executed. Specifically when you attempt to concatenate traveler_attractions[i] to interests_string. The error message tells you exactly what the problem is. You can’t concatenate a list to a string. Try printing traveler_attractions[i] prior to the line that concatenates it to the string. (See above if needed.) Is the value what you expected?

2 Likes

Thank a lot! Now my code run without any errors.

1 Like