Reputation: 40
I am having some issues with displaying images for Rock - Paper - Scissors. I'm very new to python (3 weeks) and I am trying to print a multiple line 'image'.
Please excuse my terrible art!
import random
def Display_Rock():
print ("""\n
_---___
/ .#.... \
/ .$../\.. \
|_________/
""")
def Display_Paper():
print ("""\n
__________
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|__________|
""")
def Display_Scissors():
print ("""\n
_----_
/ /--\ \
| \__/ \_________________
\____ \
/ ------------------\
/ /--\ _________________/
| \__/ /
\-____-/
""")
Display_Rock()
Display_Scissors()
Display_Paper()
This displays the following -
_---___
/ .#.... / .$../\.. |_________/
----_
/ /--\ \
| \__/ \_________________
\____ / ------------------ / /--\
_________________/
| \__/ /
\-____-/
__________
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|__________|
Thank you for reading and for any comments in advance!
Upvotes: 1
Views: 49
Reputation: 134056
While the others are correct, you can also escape the \
so that it is not treated specially by adding another \
:
print ("""\n
_----_
/ /--\ \\
| \__/ \_________________
\____ \\
/ ------------------\\
/ /--\ _________________/
| \__/ /
\-____-/
""")
In future Python versions the \
cannot be used unescaped, so starting from 3.6 a warning will be emitted for \_
, \-
and \
, so from there on you must always use \\
to mean \
; alternatively you can use the r''
raw strings; though then you cannot use \n
for newline.
Upvotes: 1
Reputation: 26961
Use r
before of your strings like so:
def Display_Rock():
print (r"""
_---___
/ .#.... \
/ .$../\.. \
|_________/
""")
>>> Display_Rock()
_---___
/ .#.... \
/ .$../\.. \
|_________/
Python treats your \
as escape chars.
Upvotes: 1