views:

115

answers:

4

I downloaded and installed Python 3.1.2 on Windows 7 x64. But it seems that it's not working as expected, for example:

alt text

Please help me figure out, what's wrong here?

+8  A: 

Try this:

>>> print "Today's stock price: %f" % 50.4625
  File "<stdin>", line 1
    print "Today's stock price: %f" % 50.4625
                                  ^
SyntaxError: invalid syntax
>>> print("Today's stock price: %f" % 50.4625)
Today's stock price: 50.462500

Python 3.X changed how print works, and now requires parentheses around the arguments.

Zonda333
You saved my life. I have to wait 10 minutes to accept this answer :)
Vimvq1987
I'm getting an error when trying to edit my post, but you can check here: http://docs.python.org/dev/whatsnew/3.1.html for other changes.
Zonda333
new format style: print("Today's stock price: {0}".format(50.4625))
histrio
+4  A: 

Python 3.X is not backward-compatible with Python 2.X. Make sure you are reading a 3.X tutorial, or remove 3.X and install 2.X.

Here's some reading about why there are differences and to decide which to use: http://wiki.python.org/moin/Python2orPython3.

Mark Tolonen
A: 

As stated above python 3.x now requires all statements such as those to be function calls, Python 3.x is supposed to bring back the functional aspect of C to python although code that works in 3.x will most likely work in 2.x but not necessarily the other way around.

Jesus Ramos
+1  A: 

In Python 3.x, print is now function and needs ().

asd32