EduPadi logo
Home Pricing Free Resources
Blog
For Schools Get started

Pass IELTS, JAMB, WAEC, & more with EduPadi CBT App

Practice questions, get instant scores, understand solutions with smart AI insights, and track your progress.

Explore EduPadi App…

How would you modify the code example provided ...

How would you modify the code example provided to write data in separate lines?

You can modify the code by adding newline characters ("\n") at the end of each piece of data to ensure they are written on separate lines in the file. Here's how the modified code would look:

 

python Copy code

# Step 1: Open the file for writing

file = open("sequential_file.txt", "w")

 

# Step 2: Write data to the file

data1 = "Hello, "

data2 = "world!"

file.write(data1 + "\n")

file.write(data2 + "\n")

 

# Step 3: Close the file

file.close()