Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python basic program problem

Reply
Thread Tools

Python basic program problem

 
 
Amaninder Singh
Guest
Posts: n/a
 
      06-27-2011
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
>>>

 
Reply With Quote
 
 
 
 
Noah Hall
Guest
Posts: n/a
 
      06-27-2011
On Mon, Jun 27, 2011 at 8:05 AM, Amaninder Singh <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Daniel Kluev
Guest
Posts: n/a
 
      06-27-2011
On Mon, Jun 27, 2011 at 6:05 PM, Amaninder Singh <(E-Mail Removed)> 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
 
Reply With Quote
 
Andrew Berg
Guest
Posts: n/a
 
      06-27-2011
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')
 
Reply With Quote
 
Noah Hall
Guest
Posts: n/a
 
      06-27-2011
On Mon, Jun 27, 2011 at 11:18 PM, Amaninder Singh <(E-Mail Removed)> 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 <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get inputs for a python program that run from another python program pradeep nair Python 2 06-12-2007 01:20 PM
How to turn a C++ program into a BASIC program ??? Ron Main C++ 7 12-18-2005 03:28 AM
Re: Python interpreter in Basic or a Python-2-Basic translator. rrr@ronadam.com Python 0 05-02-2005 01:48 PM
Python interpreter in Basic or a Python-2-Basic translator. Engineer Python 6 05-01-2005 10:16 PM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments