Function isn't returning values

Hello fellow coders!

I have one simple, but annoying question regarding the project Boredless Tourist:

https://www.codecademy.com/workspaces/6420b697eb0de81ad550b9d2

for some reason, the call to ‘find_attractions’ inside ‘get_attractions_for_traveler’ is not returning any value, which makes the string return incomplete. I’ve tried everything I can, but this isn’t working. Odd thing is: the function works, but not inside…

Thank you in advance for this helo

  • The traveler’s interests (whether single interest or multiple interests) are expected to be passed as a list.
    ["monument"] instead of "monument"
# You wrote:
smills_france = get_attractions_for_traveler(
['Dereck Smill', 'Los Angeles, USA', 'monument'])

# It should be:
smills_france = get_attractions_for_traveler(
['Dereck Smill', 'Los Angeles, USA', ['monument']])

To see what happens when you pass the interests as a string (as opposed to a list), then in the find_attractions function, add a print statement for debugging. It will show you iterating over the characters of a string as opposed to the desired behavior of iterating over the strings in a list.

for interest in interests:
      print(interest)  # <--- For debugging
      if interest in attraction_tag:
        attractions_with_interest.append(possible_attraction[0])
  • You have chosen the traveler’s location to be 'Los Angeles, USA' and his interests as ['monument']. But in the current code, there are no attractions in L.A. with a tag of "monument". The attractions in L.A. have tags of ['beach'] and ['art', 'museum'] .

  • The following code also needs to be revisited:

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

In its current form, i doesn’t refer to an index. If you want to use i as an index, consider changing it to:

for i in range(len(traveler_attractions)):

Fantastic!

Thank you for your help.

1 Like