I am making an text based rpg/adventure game and i want to add some ASCII art. I have used triple quotation marks for a multiline string like so:
print("""
/\ /\ /\ /\
/**\ /**\ /**\ /**\
/****\ /\ /\ /****\ /\ /****\ /\ /\ /****\ /\
/ \ /**\ / \ / \ /**\ / \ /**\ / \ / \ /**\
/ /\ / \ / \ / /\ / \ /\ / /\ / \ / \ / /\ / \
/ / \ / \/ \/ / \ / \ / \ / / \ / \/ \/ / \ / \
/ / \/ /\ \ / / \/ /\ \/ \/ / \/ /\ \ / / \/ /\ \
/ / \/ \/\ \ / / \/ \/\ \ / / \/ \/\ \ / / \/ \/\ \
__/__/_______/___/__\___\__/__/_______/___/__\___\___/__/_______/___/__\___\__/__/_______/___/__\___\_
""")
Ideally, this is what it should look like when i run the program.
However, it looks like this instead which is not ideal at all and looks extremely messy:
I was wondering if anyone could point me in the right direction on how to go about this problem. Thanks in advance!
The main problem in your code is that the \
at the end of the lines is interpreted as a line continuation, so the next line just gets concatenated to the previous one.
You can avoid this by adding any character at the end of the line, after the backslash, like a space for example (as the line continuation is triggered only if the backslash is the last character in the line).
Another solution is to use a raw string, starting with r""" ....
. As stated in the documentation:
Specifically, a raw literal cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the literal, not as a line continuation. (emphasis mine)
This will also prevent any potential escape sequence starting with a backslash to be interpreted as such.