Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Dungeon Game Line endings

Print each item on the same line unless the item is a double pipe (||). In that case, instead of printing the item, prin

Can you tell me what I am doing wrong.

Thanks.

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

1 Answer

The values in TILES are strings. Each item is closed in ' '. If you want x to check for the double pipe then set x='||'

x = '||'

later you call format on tile but I don't see where tile is created, so this would throw an error

HINT: When using print() it will automatically start a new line, unless you give it an extra parameter called end. If you set end = "" there will be no line return.

some_list = ['P', 'y', 't', 'h', 'o', 'n']
# default printing includes line return
for item in some_list:
    print(item)
# use optional end parameter
for item in some_list:
    print(item, end="")
>>> some_list = ['P', 'y', 't', 'h', 'o', 'n']
>>> for item in some_list:
...     print(item)
...
P
y
t
h
o
n

>>> for item in some_list:
...     print(item, end="")
...
Python