Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print with """
#1
Hi to everyone. I am absolute new in programming and Python. A started to learn it with one textbook, and one of the first exercises was printing multiple lines with triple quotes. And here the strange thing comes: the word "game" is printed normally, the word "over" is not printed normally. Why is it? How can I fix it? Thank you for your answers.
For words see the picture:
[Image: f04518a59afafef73130dc95c7b84690-full.png]
Reply
#2
For words, please copy and paste. Use BBCode tags to format code or output.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Here is the code:
print("Program 'Game Over' 2.0")
print('''
   __________           _______              ____   _____      ___________
  /          |         /       |            /    | /     |    |           |
 /    _______|        /   _    |           /     |/      |    |    _______|
 |   |               /   / |   |          /  /|     /|   |    |   |
 |   |              /   /__|   |         /   /|    / |   |    |   |_____
 |   |    ___      /   ____    |        /   / |___/  |   |    |    _____|
 |   |   |   |    /   /    |   |       /   /         |   |    |   |
 |   |___|   |   /   /     |   |      /   /          |   |    |   |_______
  \         /   /   /      |   |     /   /           |   |    |           |
   \_______/   /___/       |___|    /___/            |___|    |___________|

    _________       ___        ___     ___________      _______
   /         \     |   |      /   /   |           |    |       \
  /     _     \    |   |     /   /    |    _______|    |   |\   \
  |    / \    |    |   |    /   /     |   |            |   | \   \
  |    | |    |    |   |   /   /      |   |_____       |   |_/   /
  |    | |    |    |   |  /   /       |    _____|      |        /
  |    | |    |    |   | /   /        |   |            |   |\   \
  |    \_/    |    |   |/   /         |   |_______     |   | \   \
  \           /    |       /          |           |    |   |  \   \
   \_________/     |______/           |___________|    |___|   \___\
   ''')
In this message the output seems to be correct (therefore I didn't put it here), but in Spider and in the console it is not. Why?
Reply
#4
In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return.
Put an r in front of the string to make it a raw string it will then treat the "\" as normal "\".
print("Program 'Game Over' 2.0")
print(r'''
   __________           _______              ____   _____      ___________
  /          |         /       |            /    | /     |    |           |
 /    _______|        /   _    |           /     |/      |    |    _______|
 |   |               /   / |   |          /  /|     /|   |    |   |
 |   |              /   /__|   |         /   /|    / |   |    |   |_____
 |   |    ___      /   ____    |        /   / |___/  |   |    |    _____|
 |   |   |   |    /   /    |   |       /   /         |   |    |   |
 |   |___|   |   /   /     |   |      /   /          |   |    |   |_______
  \         /   /   /      |   |     /   /           |   |    |           |
   \_______/   /___/       |___|    /___/            |___|    |___________|
 
    _________       ___        ___     ___________      _______
   /         \     |   |      /   /   |           |    |       \
  /     _     \    |   |     /   /    |    _______|    |   |\   \
  |    / \    |    |   |    /   /     |   |            |   | \   \
  |    | |    |    |   |   /   /      |   |_____       |   |_/   /
  |    | |    |    |   |  /   /       |    _____|      |        /
  |    | |    |    |   | /   /        |   |            |   |\   \
  |    \_/    |    |   |/   /         |   |_______     |   | \   \
  \           /    |       /          |           |    |   |  \   \
   \_________/     |______/           |___________|    |___|   \___\
   ''')
Another option is to use double "\\"
print("Program 'Game Over' 2.0")
print('''
   __________           _______              ____   _____      ___________
  /          |         /       |            /    | /     |    |           |
 /    _______|        /   _    |           /     |/      |    |    _______|
 |   |               /   / |   |          /  /|     /|   |    |   |
 |   |              /   /__|   |         /   /|    / |   |    |   |_____
 |   |    ___      /   ____    |        /   / |___/  |   |    |    _____|
 |   |   |   |    /   /    |   |       /   /         |   |    |   |
 |   |___|   |   /   /     |   |      /   /          |   |    |   |_______
  \         /   /   /      |   |     /   /           |   |    |           |
   \_______/   /___/       |___|    /___/            |___|    |___________|
 
    _________       ___        ___     ___________      _______
   /         \     |   |      /   /   |           |    |       \\
  /     _     \    |   |     /   /    |    _______|    |   |\   \\
  |    / \    |    |   |    /   /     |   |            |   | \   \\
  |    | |    |    |   |   /   /      |   |_____       |   |_/   /
  |    | |    |    |   |  /   /       |    _____|      |        /
  |    | |    |    |   | /   /        |   |            |   |\   \\
  |    \_/    |    |   |/   /         |   |_______     |   | \   \\
  \           /    |       /          |           |    |   |  \   \\
   \_________/     |______/           |___________|    |___|   \___\\
   ''')
An extra blank space in place of the doubled "\" will also work
Reply
#5
Thank you very much, I understood the problem.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020