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

end argument

i'm stuck at this point and how do i use the end argument to complete my code?

mapping.py
TILES = ('-', ' ', '-', ' ', '-', '||',
         '_', '|', '_', '|', '_', '|', '||',
         '&', ' ', '_', ' ', '||',
         ' ', ' ', ' ', '^', ' ', '||'
)
for i in TILES:
    if i == ("||"):
        print ("\n")

1 Answer

The end argument can be changed using end= followed by the new value.

By default, end is a newline (\n), but you can change it.

In this challenge, you're supposed to loop through the tiles, and if the tile is a "||", print a newline. (Note that Python by default prints a newline, so you can—and should—say print() instead of print('\n'). The second snippet prints two newlines, because Python has the end argument be \n as well!)

If the tile is not "||", you print out the tile, with the end argument being '' (an empty string). Thus Python doesn't put any end after the printing, so the tiles are all printed on the same line.

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

Thanks Alexander, your explanation is so simple to understand