The Bordless Tourist: unexpected EOF while parsing

Here’s the link to the problem:
https://www.codecademy.com/paths/computer-science/tracks/cspath-cumulative-tourism/modules/cspath-boredless-tourist/projects/the-boredless-tourist

And this is my code:

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
      
def get_traveler_location(traveler):
  traveler_destination = traveler[1]
  traveler_destination_index = get_destination_index(traveler_destination)
  return traveler_destination_index

attractions = [[] for d in destinations]
#print (attractions)

def add_attraction(destination, attraction):
  try:
    destination_index = get_destination_index(destination)
    attractions_for_destination = attractions[destination_index].append(attraction)
  except SyntaxError:
    return

print(add_attraction("Los Angeles, USA",['Venice Beach', ['beach']])

This keeps giving me this error: SyntaxError: Unexpected EOF while parsing
I can’t seem to figure out why, my code looks comparable to the code in the video too so I don’t see what I’m doing wrong here.

here, you dropped this: )

eof means end of file.
if eof/eol was unexpectedly reached (or anything else unexpectedly found) it’s because the parser was expecting something else to come first

"this is a st
1 Like

It comes down to a line that has no business being in the code, in the first place, if we’re sticking to the program and carrying out instructions. Is that line asked for? Forgive me, if it is. Needless, count the brackets and see if you get an even number.

If you do want to print something from that function, then return True in the try and False in the except. That would make sense (at least to me). If we don’t specify the error we will get to see what Python kicks out (hint: it won’t be False).

except:
    return False

All exceptions will take this exit out of the function. After some testing you can build a list of possible exceptions and have them actually return something, rather than raise a fatal exception.

Learn from the type of errors you can force this function to encounter that are run time. SyntaxError is not one of them. Things like TypeError, ValueError and likes would alert you to data issues that need to be traced back to their origins.

1 Like

Oh okay, thanks! It was part of the instructions to see if the code was working :slight_smile:

1 Like