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

Ashley Keeling
Ashley Keeling
11,476 Points

I not sure how to make this work

I don't know how to replace '||' with \n

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

for item in TILES:
    if item=='||':
        print("\n")

    print(TILES)
    break

3 Answers

Steven Parker
Steven Parker
231,236 Points

Actually just printing an empty string will give you a newline.

The trick is when you don't want the newline you have to specify the "end" parameter as an empty string.

Ashley Keeling
Ashley Keeling
11,476 Points

i have tried it as a empty string but I don't get what you mean by parameter

Steven Parker
Steven Parker
231,236 Points

if you want to print the item without a newline:

    print(item, end="")
Ashley Keeling
Ashley Keeling
11,476 Points

I have done that and it still isn't working thanks

for item in TILES:

if item=='||':

    print(item, start="")

print(TILES)
Steven Parker
Steven Parker
231,236 Points

But remember, when the item is '||' is when you do want a newline. You need an "else" condition for the other values. And the parameter that controls automatic newlines is "end", not "start".

And you probably will not want to print the entire "TILES" array at once.

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Ashley, Your for loop starts well, in the loop you have to check if the item it's not equal with '||'

for item in TILES:
    if item == '||':

Now you need to create to other variables, one which holds the end= attribute and an output attribute, both placed eventually in the print statement The end= attribute should hold a \n or an empty string

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

This is little bit tricky but after the video it can be done. I hope this helped you to understand a little bit better. happy coding

Steven Parker
Steven Parker
231,236 Points

Note: for this to work, the first line after "else" should be:

        new_line = ''

Also, the solution most students arrive at is a bit more conscise.

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Steven, Yes, you are right, it was a mistake, i should check better before saving the answer :)) Thank you.