Python Forum

Full Version: general coding error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm beginner of Python and has tried finance analytic with the book 'python for Finance'.
The following codes from the book output a syntax error:invalid error.
Does anyone know why this is outputting the error?

------------------------------------------------------------------------------
def print_statistics(a1, a2):
''' Prints selected statistics.

Parameters
==========
a1, a2 : ndarray objects
results object from simulation
'''
sta1 = scs.describe(a1)
sta2 = scs.describe(a2)
print "%14s %14s %14s" % ('statistic', 'data set 1', 'data set 2')
print 45 * "-"
print "%14s %14.3f %14.3f" % ('size', sta1[0], sta2[0])
print "%14s %14.3f %14.3f" % ('min', sta1[1][0], sta2[1][0])
print "%14s %14.3f %14.3f" % ('max', sta1[1][1], sta2[1][1])
print "%14s %14.3f %14.3f" % ('mean', sta1[2], sta2[2])
print "%14s %14.3f %14.3f" % ('std', np.sqrt(sta1[3]), np.sqrt(sta2[3]))
print "%14s %14.3f %14.3f" % ('skew', sta1[4], sta2[4])
print "%14s %14.3f %14.3f" % ('kurtosis', sta1[5], sta2[5])
------------------------------------------------------------------------------

File "<ipython-input-42-2f1e93a3fe96>", line 11
print "%14s %14s %14s" % ('statistic', 'data set 1', 'data set 2')
^
SyntaxError: invalid syntax
Your books is for python 2 and you are running python 3. You can use print with parentheses: print("foo")