This post if for some questions on the Boredless Tourist python project, link is [https://www.codecademy.com/paths/computer-science/tracks/cspath-cumulative-tourism/modules/cspath-boredless-tourist/projects/the-boredless-tourist]here. I started a new thread because I didn’t want to see any extra spoilers yet. This is primarily to see if my cabeza is in the right place.
In step 29 and 30, the instructions call for a try/except block to be added. Steps 31 and 32 call for what happens if the try block is successful. My code as originally written, which kicked out an error:
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
I might have been confusing the sequence of instruction for the sequence of the code, but am I correct in understanding that, in a
try/except block, everything the function needs to do is placed into the
try block? And the
except block will essentially end the function. The way I wrote it was basically 1) try to get index, 2) if ValueError,
return, 3) if no error, do the next two steps, which python didn’t like.
And the try block here doesn’t require a
return attractions_for_destination because it’s appending to a global list?
Secondly, starting at step 38 the instructions call for the
find_attractions() function to be created. Step 42 calls for the first
for loop, and asks matches to be saved to a temporary variable. Here is what I originally wrote, which didn’t work:
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 = attractions_in_city.append(attraction) for pa in posible_attraction: attraction_tag = pa
Would ‘local variable’ be a better phrase than ‘temporary variable’ for this? My understanding is that temporary variables are located in the
And I see now that that code doesn’t work because
.append() would create a list of possible attractions, which isn’t what we need. The phrase ‘saving each’ in step 42 of the instructions initially led me to think it was looking for a list.