The boredless tourist

Hi, this is my 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

attractions =
for destination in destinations:

def add_attraction(destination, attraction):
destination_index = destinations.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:

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 " + str(traveler_attractions) + “.”
interests_string += "the " + str(traveler_attractions[i]) + ", "
return interests_string

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


for some reason the attraction part of my code prints in list form so it saya [ arc de triopmhe ] as opposed to arc de triomphe, can someone check my code and tell me how I could fix it?

You need to replace the following line:

interests_string += "the " + str(traveler_attractions) + “.”


interests_string += "the " + traveler_attractions[i] + “.”

hope this helps! :slight_smile:

1 Like

It did thanks, if you don’t mind can you explain why adding [i] or in general the change in the code matters?

The [i] change in the corrected code is used to access the individual elements of the traveler_attractions list, one at a time. In the original code, you were attempting to convert the entire traveler_attractions list to a string using str(traveler_attractions). This resulted in a string representation of the entire list object, including the brackets around the list elements.

By using traveler_attractions[i] in the corrected code, you’re able to access each individual element of the list and concatenate it to the interests_string variable without including the brackets. This is because traveler_attractions[i] returns a single element of the list at a time, as a string.

So, in summary, the [i] change allows you to access each individual element of the traveler_attractions list, which can be concatenated to the interests_string variable as a string. By doing so, you avoid the brackets that were present in the original code when using str(traveler_attractions) to convert the entire list object to a string.

I hope this answers your question. feel free to ask any follow ups.

1 Like