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 trialAshley Keeling
11,476 PointsI not sure how to make this work
I don't know how to replace '||' with \n
TILES = ('-', ' ', '-', ' ', '-', '||',
'_', '|', '_', '|', '_', '|', '||',
'&', ' ', '_', ' ', '||',
' ', ' ', ' ', '^', ' ', '||'
)
for item in TILES:
if item=='||':
print("\n")
print(TILES)
break
3 Answers
Steven Parker
231,269 PointsActually just printing an empty string will give you a newline.
The trick is when you don't want the newline you have to specify the "end" parameter as an empty string.
Ashley Keeling
11,476 PointsI have done that and it still isn't working thanks
for item in TILES:
if item=='||':
print(item, start="")
print(TILES)
Steven Parker
231,269 PointsBut remember, when the item is '||' is when you do want a newline. You need an "else" condition for the other values. And the parameter that controls automatic newlines is "end", not "start".
And you probably will not want to print the entire "TILES" array at once.
Oszkár Fehér
Treehouse Project ReviewerHi Ashley, Your for loop starts well, in the loop you have to check if the item it's not equal with '||'
for item in TILES:
if item == '||':
Now you need to create to other variables, one which holds the end= attribute and an output attribute, both placed eventually in the print statement The end= attribute should hold a \n or an empty string
for item in TILES:
if item == '||':
new_line = '\n'
output = ''
else:
new_line = ''
output = item
print(output, end=new_line)
This is little bit tricky but after the video it can be done. I hope this helped you to understand a little bit better. happy coding
Steven Parker
231,269 PointsNote: for this to work, the first line after "else" should be:
new_line = ''
Also, the solution most students arrive at is a bit more conscise.
Oszkár Fehér
Treehouse Project ReviewerHi Steven, Yes, you are right, it was a mistake, i should check better before saving the answer :)) Thank you.
Ashley Keeling
11,476 Pointsthanks I get it now
Ashley Keeling
11,476 PointsAshley Keeling
11,476 Pointsi have tried it as a empty string but I don't get what you mean by parameter
Steven Parker
231,269 PointsSteven Parker
231,269 Pointsif you want to print the item without a newline:
print(item, end="")