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

SungJin Kim
seal-mask
.a{fill-rule:evenodd;}techdegree
SungJin Kim
Front End Web Development Techdegree Student 1,905 Points

Not sure why this is not passing

is there something wrong with my code?

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

1 Answer

SungJin Kim - There seems to be a pretty consistent amount of confusion related to the print() function implemented with Python3, especially with this Challenge in particular. Even I had some issue with it initially, but it seems to stem from a misunderstanding about how print() was implemented (see docs) within Python and what the Challenge asks for. The function, print(), is described as defaulting to end='\n', meaning that, if left unchanged, each time the print() is called, regardless of content, it will automatically print at least that one newline. Your code basically amounts to print('\n', end='\n') in your if-conditional, so you're printing 2 lines rather than the 1 it asks for in the Challenge task. You should be able to figure out a solution that works for you, but if you still don't quite grasp it, feel free to let me know :)