The boredless tourist interests string

hey guys i am doing the boredless tourist.

https://www.codecademy.com/paths/computer-science/tracks/cspath-cumulative-tourism/modules/cspath-boredless-tourist/projects/the-boredless-tourist

I am basically finished, but getting an error with the final output of the interests sting. the output looks like:

Hi Dereck Smill, we think you'll like these places around Paris, 
France: the A, the r, the c, the  , the d, the e.the  , the T, 
the r, the i, the o, the m, the p, the h, the e.

I have watch the help video and double checked my code. i did make some changes so it was the same as in the video and it did not solve the problem. I have been staring at it for hours… I can figure out how its breaking “Arc de Triomphe” into single letters.

My code for the project is :

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 

#print(get_destination_index("vancouver, canada"))

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 place in destinations]


def add_attraction(destination, attraction):
  try:
    destination_index = get_destination_index(destination)
    attractions_for_destination = attractions[destination_index].append(attraction)
  except SyntaxError:
      return
  
  
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", ["SĂŁo Paulo Zoo", ["zoo"]])
add_attraction("Sao 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 = possible_attraction[0]
  return attractions_with_interest

find_attractions("Los Angeles, USA", ["art"])

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)








I would love some help trying to figure this put, thanks in advance

If you loop through a string it will use each character as a single element, e.g.

for character in 'eggs':
    print(character)
# Output occurs like this-
e
g
g
s

At some point you probably expect a list but have wound up with a string instead. You’d want to look up where this printing/looping occurs and what variable it is that you’re iterating through. If you print this variable (or its type) is it still what you expect it to be?

well for the after hours of trying i made my code the exact same as in the tutorial video and his code works. for the string saved in the variable interests string, if i take out the parts that add the word “the” and the commas and periods it prints out fine.
so the problem area is somewhere in here

if i write it this way

for i in range(len(traveler_attractions)):
      interests_string +=traveler_attractions[i] 
return interests_string

the output will be :

Hi Dereck Smill, we think you’ll like these places around Paris, France: Arc de Triomphe

if i just add the period to the string like this:

  for i in range(len(traveler_attractions)):
      interests_string += traveler_attractions[i] + "." 
  return interests_string

the result is:

Hi Dereck Smill, we think you’ll like these places around Paris, France: A.r.c. .d.e. .T.r.i.o.m.p.h.e.

in the help video i used the same code exactly as i just copied exactly what he wrote and it works fine for him but not me

   if traveler_attractions[-1] == traveler_attractions[i]:
      interests_string += traveler_attractions[i] + "."
   else:
      interests_string += "the " + traveler_attractions[i] + ", "
   return interests_string

so i am really lost. i can actually pass the lesson as the extra work for making the string with periods and commas isnt actually required but i would like to find where the error is.

Your problem is that something you expect to be a list is not a list. Where do you get traveler_attractions from? Does it actually perform as you expect? I think you’re looking at the wrong location and making assumptions about your variables. Try printing them out or similar to make sure things are as you expect.

yes i have tried here in this way without the extra parts of the string and it produce the correct results

as you can see the output is correct:

where it goes wrong is when concactinate the string with the exact same code as in the video like this:

i guess its just one thing i will never figure out… as my skill level is still too low. have litterally retyped out the entire program word for word as was done in the training video and it works in the training video but not here.

traveler_ attractions comes from these lists

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", ["SĂŁo Paulo Zoo", ["zoo"]])
add_attraction("Sao 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"]])

and this function was used, and part of the lesson makes us test this function which tested ok:

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 = possible_attraction[0]
  return attractions_with_interest

Try using find_attractions outside your new function. What does it return?

ok i have found the error thanks for the help i used a equals sign when i should of used append…

without the help of these forums i would probably have never found it. because the way i was testing for errors gave me the correct answer i assumed the problem was in my string layout…
thanks again

1 Like