SyntaxError

This is the place for queries that don't fit in any of the other categories.

SyntaxError

Postby learner79 » Wed Feb 13, 2013 9:52 pm

hi i have be following a book but the code has been written in python 2.2 the problem is when I run tyhe code i keep getting the following error SyntaxError: multiple statements found while compiling a single statement
this is the code I have been using
Code: Select all
print ("New improved 'Game Over' Program")
print (\"""
   
    _____         ___           __        _  ____
   / ____|      /   |          / | |  // ||  __|
   | |           / /| |       / /|  |//| || |__
   | |  _      / /_| |     / / |    /  | ||     |
   | |_| |  / /      |   / /  |__/   | ||  __| 
   |     |   / /   | |   / /              | || |__ 
   \____//_/    |_|/_/               |_||____|

      ____   __      __    ____   ____
     /  _  \ | |    / /   |  __|  |  _  \
    | | | | | |   / /    | |__   | | | |
    | | | | | |  / /     |      | | |_| |
    | | | | | | / /      |  __|  |  _  /
    | |_| | | |/ /      | |__   | | \ \
    \____/ |___/      |____| |_|  \_\
    """)
 input( "\n\nPress The Enter Kay To Exit." )

I wonder if someone could be so kind as to point out where it is I'm going wrong
learner79
 
Posts: 2
Joined: Wed Feb 13, 2013 9:34 pm

Re: SyntaxError

Postby metulburr » Wed Feb 13, 2013 9:56 pm

python2.2 is old old old. I normally would suggest to stick it out, but i would suggest a newer version book than 2.2


save the triple quote as a var and print the var
This runs in both python 2.7 and python 3.x
Code: Select all
print("New improved 'Game Over' Program")
game_over = """
   
    _____         ___           __        _  ____
   / ____|      /   |          / | |  // ||  __|
   | |           / /| |       / /|  |//| || |__
   | |  _      / /_| |     / / |    /  | ||     |
   | |_| |  / /      |   / /  |__/   | ||  __|
   |     |   / /   | |   / /              | || |__
   \____//_/    |_|/_/               |_||____|

      ____   __      __    ____   ____
     /  _  \ | |    / /   |  __|  |  _  \
    | | | | | |   / /    | |__   | | | |
    | | | | | |  / /     |      | | |_| |
    | | | | | | / /      |  __|  |  _  /
    | |_| | | |/ /      | |__   | | \ \
    \____/ |___/      |____| |_|  \_\
    """
print(game_over)
input( "\n\nPress The Enter Kay To Exit." )
New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
User avatar
metulburr
 
Posts: 1103
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: SyntaxError

Postby micseydel » Wed Feb 13, 2013 11:07 pm

Just to be explicit, the problem was right here
Code: Select all
print (\"""

You were escaping a double-quote outside of a string. This doesn't really make sense, since a backslash like that basically says "ignore the next character" or in the case of \n, more of a modification.

In any case, as metulburr showed, you didn't need to escape anything or use a paren, just triple double-quotes.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 929
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: SyntaxError

Postby learner79 » Fri Feb 15, 2013 11:37 am

thank you both for your help I feel bit of idiot know you both pointed out where i was going wrong.
learner79
 
Posts: 2
Joined: Wed Feb 13, 2013 9:34 pm

Re: SyntaxError

Postby micseydel » Fri Feb 15, 2013 5:01 pm

learner79 wrote:thank you both for your help I feel bit of idiot know you both pointed out where i was going wrong.

Hey, we all start somewhere!
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 929
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests