Question

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 ("'--.______.--'")
Was it helpful?

Solution

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    '--.______.--'
''')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top