EOL whilst scanning string literal - Python

1.3k views Asked by At

I'm new to Python. I'm trying to make code it so it will print out this ASCII art traffic light, here is the actual ASCII

  ##
                  _[]_
                 [____]
             .----'  '----.
         .===|    .==.    |===.
         \   |   /####\   |   /
         /   |   \####/   |   \
         '===|    `""`    |==='
         .===|    .==.    |===.
         \   |   /::::\   |   /
         /   |   \::::/   |   \
         '===|    `""`    |==='
         .===|    .==.    |===.
         \   |   /&&&&\   |   /
         /   |   \&&&&/   |   \
         '===|    `""`    |==='
      jgs    '--.______.--'

And the Code I'm trying to use is this

print ("##"),
print (" _[]_"),
print (".----'  '----."),
print (" .===|    .==.    |===."),
print (" \   |   /####\   |   /"),
print (" /   |   \####/   |   \\"),
print ("'===|    `""`    |==='"),
print (" .===|    .==.    |===."),
print ("\   |   /::::\   |   /"),
print (" /   |   \::::/   |   \"),
print ("'===|    `""`    |==='"),
print (".===|    .==.    |===."),
print (" \   |   /&&&&\   |   /"),
print (" /   |   \&&&&/   |   \"),
print (" '===|    `""`    |==='"),
print ("'--.______.--'")
1

There are 1 answers

11
Martijn Pieters On BEST ANSWER

You need to escape the \ characters, double them:

print (" /   |   \::::/   |   \"),

should be:

print(" /   |   \\::::/   |   \\")

You want to get rid of all the commas too.

Note that you can create a multiline string using triple quotes; make it a raw string (using r'') and you don't have to escape anything either:

print(r'''              _[]_
             [____]
         .----'  '----.
     .===|    .==.    |===.
     \   |   /####\   |   /
     /   |   \####/   |   \
     '===|    `""`    |==='
     .===|    .==.    |===.
     \   |   /::::\   |   /
     /   |   \::::/   |   \
     '===|    `""`    |==='
     .===|    .==.    |===.
     \   |   /&&&&\   |   /
     /   |   \&&&&/   |   \
     '===|    `""`    |==='
  jgs    '--.______.--'
''')