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

what is wrong with my code?

Could you help me out here, please?

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

1 Answer

Hi Ian,

You missed a colon (edited!) at your if statement line. You also don't want to output the || if one is reached, so set tile to '' in that scenario.

My code looked like:

for tile in TILES:
    line_end = ''
    if tile == '||':
        tile = ''
        line_end = "\n"
    print(tile, end=line_end)

Yours can be easily modified to do the same thing:

for tile in TILES:
    if tile == '||':
        tile = ""
        line_end = "\n"
    else:
        line_end = ""
    print(tile, end=line_end)

I hope that helps,

Steve.

Oh, and don't set line_end to be a space, either, in your else bit.