Python basic program problem

Discussion in 'Python' started by Amaninder Singh, Jun 27, 2011.

  1. Hi,
    I am fairly new to python, I am trying to write simple code and It is
    giving me syntax error. I am reading a book and following the
    directions as it says in the book but I am not sure why it is not
    working. Please guide me through. Any help appreciated.
    >>> x = 2
    >>> if x == 2:

    print "This is a test"

    SyntaxError: invalid syntax
    >>> if x == 2:

    print "This is a test"

    SyntaxError: invalid syntax
    >>> x = 2
    >>> if x = 2:


    SyntaxError: invalid syntax
    >>> if x == 2:

    print "This is test"

    SyntaxError: invalid syntax
    >>> Type "copyright", "credits" or "license()" for more information.

    SyntaxError: invalid syntax
    >>>
    >>>
    >>> print "this is a test"

    SyntaxError: invalid syntax
    >>> import keyword
    >>> print keyword.kwlist

    SyntaxError: invalid syntax
    >>> print "hellow world"

    SyntaxError: invalid syntax
    >>> print 'hellow world'

    SyntaxError: invalid syntax
    >>>
    Amaninder Singh, Jun 27, 2011
    #1
    1. Advertising

  2. Amaninder Singh

    Noah Hall Guest

    On Mon, Jun 27, 2011 at 8:05 AM, Amaninder Singh <> wrote:
    > Hi,
    > I am fairly new to python, I am trying to write simple code and It is
    > giving me syntax error. I am reading a book and following the
    > directions as it says in the book but I am not sure why it is not
    > working. Please guide me through. Any help appreciated.
    >>>> x = 2
    >>>> if x == 2:

    >   print "This is a test"
    >
    > SyntaxError: invalid syntax
    >>>> if x == 2:

    >           print "This is a test"
    >
    > SyntaxError: invalid syntax
    >>>> x = 2
    >>>> if x = 2:

    >
    > SyntaxError: invalid syntax
    >>>> if x == 2:

    >        print "This is test"
    >
    > SyntaxError: invalid syntax
    >>>> Type "copyright", "credits" or "license()" for more information.

    > SyntaxError: invalid syntax
    >>>>
    >>>>
    >>>> print "this is a test"

    > SyntaxError: invalid syntax
    >>>> import keyword
    >>>> print keyword.kwlist

    > SyntaxError: invalid syntax
    >>>> print "hellow world"

    > SyntaxError: invalid syntax
    >>>> print 'hellow world'

    > SyntaxError: invalid syntax
    >>>>

    Looks like you're using the 3.x version, while your guide is 2.x. I
    suggest you download the 2.x version, or find a new tutorial.

    HTH
    Noah Hall, Jun 27, 2011
    #2
    1. Advertising

  3. Amaninder Singh

    Daniel Kluev Guest

    On Mon, Jun 27, 2011 at 6:05 PM, Amaninder Singh <> wrote:
    >>>> print "this is a test"

    > SyntaxError: invalid syntax


    Most likely, you are running python 3.x, while reading python 2.x book.
    In python 3.x print is now ordinary function,

    >>> print('hello world')

    hello world


    In future, please include full tracebacks and python version info.

    --
    With best regards,
    Daniel Kluev
    Daniel Kluev, Jun 27, 2011
    #3
  4. Amaninder Singh

    Andrew Berg Guest

    On 2011.06.27 02:05 AM, Amaninder Singh wrote:
    > Hi,
    > I am fairly new to python, I am trying to write simple code and It is
    > giving me syntax error. I am reading a book and following the
    > directions as it says in the book but I am not sure why it is not
    > working.

    Looks like the book you're reading is outdated and refers to Python 2.
    In Python 3, print is a function:
    print('Hello there')
    Andrew Berg, Jun 27, 2011
    #4
  5. Amaninder Singh

    Noah Hall Guest

    On Mon, Jun 27, 2011 at 11:18 PM, Amaninder Singh <> wrote:
    > Yes, I think I am using 3.0 version. So how much difference is in between these two?
    > On Jun 26, 2011, at 11:18 PM, Noah Hall wrote:
    >> On Mon, Jun 27, 2011 at 8:05 AM, Amaninder Singh <> wrote:
    >>> Hi,
    >>> I am fairly new to python, I am trying to write simple code and It is
    >>> giving me syntax error. I am reading a book and following the
    >>> directions as it says in the book but I am not sure why it is not
    >>> working. Please guide me through. Any help appreciated.

    >> Looks like you're using the 3.x version, while your guide is 2.x. I
    >> suggest you download the 2.x version, or find a new tutorial.



    Well, quite a lot. Read this -
    http://wiki.python.org/moin/Python2orPython3 to get a better picture.
    Noah Hall, Jun 27, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Berg
    Replies:
    1
    Views:
    513
    Sudsy
    Nov 23, 2003
  2. Engineer
    Replies:
    6
    Views:
    613
    Jeremy Bowers
    May 1, 2005
  3. Replies:
    0
    Views:
    428
  4. Ron Main
    Replies:
    7
    Views:
    321
  5. pradeep nair
    Replies:
    2
    Views:
    542
Loading...

Share This Page