-5
coord  =  {'latitude' : '37.24N' , 'longitude' : '-115.81'} 
print 'coordinates:  {latitude},  {longitude}' .format(**coord)

I've been recently following this new program on learning python and I've come across an error that says SyntaxError: invalid syntax,but I can't spot any syntax errors, if anyone can offer help it would be much appreciated.

ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
  • 3
    Works fine for me: https://repl.it/repls/ItchyFamiliarLock – jpp Jun 10 '18 at 15:06
  • Works for me too. Output: `coordinates: 37.24N, -115.81` – rst-2cv Jun 10 '18 at 15:06
  • 5
    This only gives a syntax error on Python 3, works fine with Python 2. Are you sure you're not using Python 3? – Thierry Lathuille Jun 10 '18 at 15:09
  • ^ Note that python3 will give a syntax error because it's missing the parentheses required to use the `print()` function, in which case the correct syntax would be `print ('coordinates: {latitude}, {longitude}'.format(**coord))` – rst-2cv Jun 10 '18 at 15:11
  • i am using the python shell , is that whats making give the error?? because i did try all of these solutions but none of them worked – oldamilyas Jun 10 '18 at 15:15
  • It makes no difference whether it's run via the interpreter (the shell as you describe it) or by running it via a file. – rst-2cv Jun 10 '18 at 15:17
  • 1
    You labeled the question as `python 2.7`. This error occurs only in `Python 3`. Now, check what this prints out: `import platform; print(platform.python_version())`. Soes it say something like `2.7.3`, or is it Python 3 after all? – zvone Jun 10 '18 at 15:21
  • 1
    @oldamilyas check the version then, `python --version` – amin Jun 10 '18 at 15:21

1 Answers1

-1

I'm guessing that you are getting a syntax error related to the print statement if you are using the wrong version of Python. Make sure you are using Python 2.x, otherwise upgrade your code to be compatible with Python 3.x.

python --version should tell you which version you are using

Python 3.x version of your code. Notice the round brackets used with the print statement.

coord  =  {'latitude' : '37.24N' , 'longitude' : '-115.81'} 
print('coordinates:  {latitude},  {longitude}'.format(**coord))
reka18
  • 7,440
  • 5
  • 16
  • 37
  • It's impossible to answer the question when we haven't even ascertained the exact issue the OP is running into. – rst-2cv Jun 10 '18 at 15:23
  • 1
    It's reasonable to assume his problem has to do with python version and the print statement. – reka18 Jun 10 '18 at 15:25