Boredless Tourist - trouble defining find_attractions


#1

I’m working on the Python Boredless Tourist project in the CS Path.

I’ve gotten to the step of creating the find_attractions function, and can’t get past setting the destination index variable. The step after that - setting attractions_in_city - is failing. I can’t figure out why. When I test it as written, I get the index but nothing returns for attractions_in_city.

Help!

destinations = ["Paris, France",
"Shanghai, China",
"Los Angeles, USA",
"So 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 = test_traveler[1]
  traveler_destination_index = get_destination_index(traveler_destination)
  return traveler_destination, traveler_destination_index

#print(get_traveler_location(test_traveler))

attractions = [[] for destination in destinations]

def add_attraction(destination, attraction):
  try:
    destination_index = get_destination_index(destination)
  except ValueError:
    return
  attractions_for_destination = attractions[destination_index]
  attractions_for_destination.append(attraction)
  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("So Paulo, Brazil", ["So Paulo Zoo", ["zoo"]])
add_attraction("So Paulo, Brazil", ["Ptio do Colgio", ["historical site"]])
add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]])
add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]])

#for x in range(len(attractions)): 
 #   print attractions[x]
  
def find_attractions(destination, interests):
  destination_index = get_destination_index(destination)
  return "destination_index is " + str(destination_index)
  **attractions_in_city = attractions[destination_index]**
**  return attractions_in_city**

print(find_attractions("Paris, France", "museum"))

#2

By default, a function returns None at the end of the function. If we want to return something else at the end of the function, we can use the return keyword.

Given return is the last thing a function does, when a return keyword is reached, the function ends