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
Daniel Kaczmarczyk
Courses Plus Student 5,536 Pointsmapping.py problem
"OK, here's a...weird...set of tiles. I need you to loop through TILES and print out each item. 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). Use the end argument to print() to control whether things print on a new line or not."
I have seen many questions regarding this challenge here, and I have followed each and every advice, yet the challenge still isn't passing. It does work as expected on my local machine, though. Here's my code:
TILES = ('-', ' ', '-', ' ', '-', '||',
'_', '|', '_', '|', '_', '|', '||',
'&', ' ', '_', ' ', '||',
' ', ' ', ' ', '^', ' ', '||'
)
for tile in TILES:
if tile != "||":
print(tile, end="")
else:
print("\n")
7 Answers
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Pointshello,
since the default for end in print() is a new line, in your else statement you are really calling print('\n', end='\n'), printing two new lines. Maybe in the else just call print().
This is probably a challenge right? there is no link to the actual challenge in the question, usually the site engineers a link so I have not looked at the challenge.
abdulkadir yıldız
2,711 PointsTILES = ('-', ' ', '-', ' ', '-', '||',
'_', '|', '_', '|', '_', '|', '||',
'&', ' ', '_', ' ', '||',
' ', ' ', ' ', '^', ' ', '||'
)
for tile in TILES:
if tile != "||":
print(tile, end="")
else:
print()
Andrew Hopkins
8,957 PointsThis is correct, however the Treehouse instructions are misleading: "In that case, instead of printing the item, print a new line (\n)." Referencing the \n suggests to the student that they are to use this in the code.
George Kim
Courses Plus Student 1,689 PointsThank you james. Now I know how end = works!
Kortney Field
14,091 Pointswhat does *** end="" *** do in your code? Does this read "end of line"?
Kortney Field
14,091 Pointsfor tile in TILES: if tile != "||": print(tile, end="") else: print()
Why does *** print(tile, end="") *** need to be in a (x,y) format to work?)
Thanks
Daniel Kaczmarczyk
Courses Plus Student 5,536 PointsThanks James! Indeed you are right, that was the right answer. Thanks for pointing this print() behaviour out. I completely forgot about it!
Tinotenda Muyengwa
3,464 Pointsthanks james that really worked ,,N/B default for end in print() is a new line.
for tile in TILES: if tile != "||": print(tile, end="") else: print()
Tinotenda Muyengwa
3,464 Pointsfor tile in TILES: if tile != "||": print(tile, end="") else: print()