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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Karen Shumate](https://secure.gravatar.com/avatar/35b3c243b7d0276e71e90dea004120cc?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Karen Shumate
13,579 PointsPrint each item on the same line unless the item is a double pipe (||). In that case, instead of printing the item, prin
How do I get it to print out?
Thanks,
TILES = ('-', ' ', '-', ' ', '-', '||',
'_', '|', '_', '|', '_', '|', '||',
'&', ' ', '_', ' ', '||',
' ', ' ', ' ', '^', ' ', '||'
)
for tile in TILES:
if tile != "||":
output = tile
else:
output = "\n"
print( end="")
1 Answer
![Timothy Long](https://secure.gravatar.com/avatar/816d506a7000905255666cd0e30549ea?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Timothy Long
Front End Web Development Techdegree Student 6,833 PointsHi Karen,
It seems you possibly misunderstood what the question is asking for.
You need to print out each item in the TILES
list unless it is '||'
. If that is the case you print a new line.
This code works:
for tile in TILES:
if tile == '||':
print('\n')
else:
print(tile, end='')
To explain my code I use a for loop to loop through each list item. I check to see if each index is equal to '||'
and if it is just print('\n')
(print only a newline character).
Then in my else block I print tile and add one argument. You can see in the Python documentation here: https://docs.python.org/3/library/functions.html#print
That the end
argument in python by default is a newline character. Changing this to end=''
gets rid of the newline and prints everything on the same line. Thus printing everything out on the same line. Unless of course the current index is == to the '||'
.
I hope this was helpful!