Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Dungeon Game Line endings

Instructions not clear on how to print?

The code shows 3 different ways on how I would solve this solution, and not one of them are correct. Each of them will produce the same result, so I am not understanding what they really want as an answer.

Of note, when I check my work, I only have one of the solutions in the code, not all 3.

mapping.py
TILES = ('-', ' ', '-', ' ', '-', '||',
         '_', '|', '_', '|', '_', '|', '||',
         '&', ' ', '_', ' ', '||',
         ' ', ' ', ' ', '^', ' ', '||'
)

print(''.join(TILES).replace('||', '\n'))
print('\n'.join(''.join(TILES).split("||")))

for item in TILES:
    if '||' in item:
        print()
    else:
        print(item, end='')

and for clarity, this was the task:

OK, here's a...weird...set of tiles. I need you to loop through TILES and print out each item. Print each item on the same line unless the item is a double pipe (||). In that case, instead of printing the item, print a new line (\n). Use the end argument to print() to control whether things print on a new line or not.

3 Answers

You almost there. You just missed

for item in TILES:
    if '||' in item:
        print('\n')          <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    else:
        print(item, end='')

make sure to remove the first 2 print statements before the for loop, or the challenge will get upset.

That worked, but that did not make any sense. print()'s default end value is '\n', so why would I want to include another '\n' in the print statement? I guess I just didn't understand what was being asked, thanks for the response.

WRONG OUTPUT:

- - -
_|_|_|
& _ 
   ^ 

CORRECT OUTPUT:

- - -

_|_|_|

& _ 

   ^ 

You actually need the extra \n so that it will print two newlines. :smile:

~Alex

Hello

you are sort of right ... bu th challenge is expecting a specific returned format. if you do not include \n the line will look like

aaaa
aaaa
aaaa

with \n

aaaa

aaaa

aaaa

to make the challenge happy ... do what the challenge wants :-)

but but... all that unnecessary white space... are we trying to fit a bus in there?? lol, thanks again for the help.