Search code examples
pythonpython-3.xsyntax-errorgeopy

Printing issue when using GeoPy


I am completely new to Python so I appreciate that I maybe making a basic mistake somewhere. When I do the below, I get a "SyntaxError: invalid syntax" error after the print line. What am I doing wrong?

import geopy.distance

coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)

print geopy.distance.distance(coords_1, coords_2).km

Solution

  • You are typing python 2 code in python 3. You need to have parentheses on the print statement.

    Code:

    import geopy.distance
    
    coords_1 = (52.2296756, 21.0122287)
    coords_2 = (52.406374, 16.9251681)
    
    print(geopy.distance.distance(coords_1, coords_2).km)
    

    Hope this helps!