Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Brandon Galde
Brandon Galde
12,741 Points

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='')
Brandon Galde
Brandon Galde
12,741 Points

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.

Brandon Galde
Brandon Galde
12,741 Points

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 :-)

Brandon Galde
Brandon Galde
12,741 Points

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