Create Purchasing Information and Receipts for Lovely Loveseats

I’m working through a project within the Python 3 course.

I’m not returning an error. My question is more related to how I can concatenate strings and not have them “squished together”. For example, on line 19, I created a variable and then I continue to use plus-equal to add to this variable (adding descriptions of the each items purchased)

customer_one_itemization = ""

My output:
Customer One Items:
Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.Luxurious Lamp. Glass and iron. 36 inches tall. Brown with cream shade.

For a cleaner look, I’d like to have Lovely Loveseat along with its description together and then Luxurious Lamp and its description on another line instead of appended to the end of the description for “Lovely Loveseat”

Like this:
Customer One Items:
Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.
Luxurious Lamp. Glass and iron. 36 inches tall. Brown with cream shade.

How can I accomplish this? Thank you.

Hi cat_collector,

I was wondering the same thing. After doing some research, I found that using the new line character, or “\n” in string variables or print statements does the trick.

So in your example it world look this:

Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.\n Luxurious Lamp. Glass and iron. 36 inches tall. Brown with cream shade.

Notice the “\n” placed in front of the word “Luxurious Lamp”.

Hope that helps. :slight_smile:

Hey - Just place a “\n” at the end of your product descriptions like so:

lovely_loveseat_description = "Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.\n"

That “\n” at the end is a line break - that’s what you’re looking for.
Do this for all your product descriptions, and you’ll get the results you’re looking for!

Happy Coding!

1 Like

I’m going to add on to what @java9048199302 and @seraph776 have said here. We should know the function and the way in which aspects of our code work rather than adding them in without understanding their mechanisms.

\n is an escape sequence. Escape sequences begin with a backslash (\) and are followed by a character or set of characters, with different characters resulting in different outputs (see the table below). \n is the newline escape sequence and moves the cursor down to the next line.

Here’s a list of all the recognized escape sequences in Python (find more about them here).

Escape Sequence Meaning
\newline Backslash and newline ignored
\\ Backslash ( \ )
\' Single quote ( ' )
\" Double quote ( " )
\a ASCII Bell (BEL)
\b ASCII Backspace (BS)
\f ASCII Formfeed (FF)
\n ASCII Linefeed (LF)
\r ASCII Carriage Return (CR)
\t ASCII Horizontal Tab (TAB)
\v ASCII Vertical Tab (VT)
\ooo Character with octal value ooo
\xhh Character with hex value hh

Side note: \n is called the newline escape sequence but inserts an ASCII linefeed (as indicated by the table above) because of terminology that was used when typewriters were commonly used. You can learn more about it for your own pleasure here.

1 Like