0

I'm trying to use code to be able to create a file called output.txt.

However, when I print the following code and then look in the actual .txt file, it prints it all on one line, which is NOT what I want.

 file2.write("*******************************************")
 file2.write("                   ""TICKET REPORT""                   ")
 file2.write("")
 file2.write("There are 6 tickets in the database.")
 file2.write("")
 file2.write("Maximum Ticket price is $179.99.")
 file2.write("Minimum Ticket price is $49.99.")
 file2.write("Average Ticket Price is $149.99.")
 file2.write("")
 file2.write("Thank you for using our ticket system!")
 file2.write("")
 file2.write("*******************************************")
 file2.close()

I want the text to print line-by-line as it shows below. Keep in mind, I'm running Windows 10.

Jake M
  • 41
  • 5
  • 1
    Possible duplicate of [Correct way to write line to file?](https://stackoverflow.com/questions/6159900/correct-way-to-write-line-to-file) – Ayesh Salahuddin Apr 11 '19 at 18:00

1 Answers1

2

Just add '\n' at the end of the line or the other solution is:

lines = [line0, line1, .... ]
fo = open("foo.txt", "rw+")
fo.writelines(lines)