[Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
Danny Yoo
dyoo at hashcollision.org
Tue Feb 17 19:43:23 CET 2015
> Dawson) Game Over 2.0 program in chapter two on page 17. The object of
> this program is to do ASCII-style art to generate a large rendition of
> "Game Over" using the following characters: "_" , "\" , "|" , and "/"
> . When my son tried to do his version, the "Over" portion did not
> print correctly.
Hi boB,
Ah ha. Escape characters. I see what you mean. :P
Just to add: there is a "raw" string literal syntax that will turn off
escape sequence handling. Using a raw string literal may make it
easier to type the value in question.
We can use raw literal strings by prepending a 'r' in the front of the
string literal. e.g.:
##########################################
>>> x = r'''
... this\
... is\
... a/
... test\
... '''
>>> x
'\nthis\\\nis\\\na/\ntest\\\n'
>>> print x
this\
is\
a/
test\
##########################################
It might be that the question is trying to motivate the use of raw
string literals, or teaching about escape sequences. I don't have the
book, so I can't say for sure.
More information about the Tutor
mailing list