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

Tom Stockwell
Tom Stockwell
217 Points

Python \n function

line1 = ("A : CHBKQBHC")
line2 = ("B : PPPPPPPP")
line3 = ("C : ▓▒▓▒▓▒▓▒")
line4 = ("D : ▒▓▒▓▒▓▒▓")
line5 = ("E : ▓▒▓▒▓▒▓▒")
line6 = ("F : ▒▓▒▓▒▓▒▓")
line7 = ("G : PPPPPPPP")
line8 = ("H : CHBQKBHC")

board = (line1, "\n", line2, "\n", line3, "\n", line4, "\n", line5, "\n", line6, "\n", line7, "\n", line8)

print(board)

My output is

('A : CHBKQBHC', '\n', 'B : PPPPPPPP', '\n', 'C : ▓▒▓▒▓▒▓▒', '\n', 'D : ▒▓▒▓▒▓▒▓', '\n', 'E : ▓▒▓▒▓▒▓▒', '\n', 'F : ▒▓▒▓▒▓▒▓', '\n', 'G : PPPPPPPP', '\n', 'H : CHBQKBHC')

I can't figure out why it isn't line breaking when I print the output, any help?

2 Answers

Josh Keenan
Josh Keenan
20,315 Points

Hey Tom, since I don't want to turn around and speak to you (I want points instead), I'll answer your question here.

line1 = "A : CHBKQBHC"
line2 = "B : PPPPPPPP"
line3 = "C : ▓▒▓▒▓▒▓▒"
line4 = "D : ▒▓▒▓▒▓▒▓"
line5 = "E : ▓▒▓▒▓▒▓▒"
line6 = "F : ▒▓▒▓▒▓▒▓"
line7 = "G : PPPPPPPP"
line8 = "H : CHBQKBHC"

board = (line1 + "\n" + line2 + "\n" + line3 + "\n" + line4 + "\n" + line5 + "\n" + line6 + "\n" + line7 + "\n" + line8)

print(board)

You created what's called a tuple, it's immutable and I believe you're trying to concatenate this as a string, so you use the '+' symbol to do this, here's how it should look!

Tom Stockwell
Tom Stockwell
217 Points

Thanks! You should really become mod...

Codin - Codesmite
Codin - Codesmite
8,600 Points

Your syntax is incorrect for concatination.

Try this:

line1 = "A : CHBKQBHC"
line2 = "B : PPPPPPPP"
line3 = "C : ▓▒▓▒▓▒▓▒"
line4 = "D : ▒▓▒▓▒▓▒▓"
line5 = "E : ▓▒▓▒▓▒▓▒"
line6 = "F : ▒▓▒▓▒▓▒▓"
line7 = "G : PPPPPPPP"
line8 = "H : CHBQKBHC"

board = line1 + "\n" + line2 + "\n" + line3 + "\n" + line4 + "\n" + line5 + "\n" + line6 + "\n" + line7 + "\n" + line8

print board