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

Abdulkadir Kollere
Abdulkadir Kollere
1,723 Points

Tiles not giving right output

This always bothers me! I get the correct output in workspaces but the challenge gives me the error "Didn't get the right output". Anyone for the rescue?

See the attached code.

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


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

2 Answers

Stuart Wright
Stuart Wright
41,120 Points

Note that the challenge states:

"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)."

You are currently printing the item as well as the new line.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

You are very close. If the tile is the double-pipe then do not print that tile. Instead print a regular EOL:

TILES = ('-', ' ', '-', ' ', '-', '||',
         '_', '|', '_', '|', '_', '|', '||',
         '&', ' ', '_', ' ', '||',
         ' ', ' ', ' ', '^', ' ', '||'
)


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