[Tutor] New to Python - print function - invalid syntax

Alan Gauld alan.gauld at btinternet.com
Tue Aug 5 02:13:46 CEST 2014


On 05/08/14 00:21, Greg Markham wrote:

>         but I'm running into a syntax error

As others have said you are getting the expected error when running 
Python v3 code under Python v2.

How exactly are you running the program? It looks like somehow you
are picking up Python v2 when you run the script even though your python 
-V is showing v3.

BTW. Which OS are you using? It shouldn't affect the cause but
it helps with the debugging!

> For clarity, the full program reads as follows:
>
>
> # Game Over - Version 2
> # Demonstrates the use of quotes in strings
> # Python Programming for the Absolute Beginner, 3rd ed - Ch 2
> # Greg Markham - Aug 04, 2014
>
> print("Program 'Game Over' 2.0")
>
> print("Same", "message", "as before")
>
> print("Just",
>        "a bit",
>        "bigger")

Does all of the above print out correctly? Can you send
us a cut n paste of the exact output of the program?


>
> print("Here", end=" ")
> print("it is...")
>
> print(
>          """
>           _____       ___       ___  ___   _____
>          /  ___|     /   |     /   |/   | |  ___|
>          | |        / /| |    / /|   /| | | |__
>          | |  _    / ___ |   / / |__/ | | |  __|
>          | |_| |  / /  | |  / /       | | | |___
>          \_____/ /_/   |_| /_/        |_| |_____|
>
>           _____   _     _   _____   _____
>          /  _  \ | |   / / |  ___| |  _  \
>          | | | | | |  / /  | |__   | |_| |
>          | | | | | | / /   |  __|  |  _  /
>          | |_| | | |/ /    | |___  | | \ \
>          \_____/ |___/     |_____| |_|  \_\
>
>          """
>       )
>
> input("\n\nPress the enter key to exit.")

finally you could try putting the following at the very top of your program:

import sys
print(sys.version)

That will definitively prove that you are actually
running v3 on the file...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list