Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
general coding error
#1
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
Reply
#2
Your books is for python 2 and you are running python 3. You can use print with parentheses: print("foo")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Coding error. xflyerwdavis 2 527 Oct-07-2023, 07:08 PM
Last Post: deanhystad
  Coding error. Can't open directory EddieG 6 1,118 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Coding Error EddieG 2 537 Jul-09-2023, 02:59 AM
Last Post: EddieG
  General Coding Help biswajitmaity 2 1,765 Aug-25-2021, 03:04 PM
Last Post: jefsummers
  python coding error isntitzee 1 2,206 Oct-17-2020, 06:30 AM
Last Post: buran
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 1,731 Sep-28-2020, 07:57 AM
Last Post: buran
  coding error iro a menu Rollo 2 2,084 Sep-27-2020, 04:17 PM
Last Post: deanhystad
  Adafruit LIS3DH coding error FitDad73 1 2,002 Aug-30-2020, 01:37 AM
Last Post: bowlofred
  General coding Ellimann 2 2,386 Aug-25-2020, 05:43 AM
Last Post: buran
  General coding help prathmesh 1 1,881 Apr-01-2020, 01:23 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020