Some Error in 3/11 - File input/output


#1



Help, I feel like my code is correct but I get the error saying: "Oops, try again. It looks like your file doesn't contain each element from my_list on its own line." Thanks

https://www.codecademy.com/en/courses/python-intermediate-en-OGNHh/0/3?curriculum_id=4f89dab3d788890003000096


Replace this line with your code.


#2

This is my code:
my_list = [i**2 for i in range(1,11)]

my_file = open("output.txt", "r+")

Add your code below!

for i in my_list:
my_file.write(str(i)+"\n")
my_file.close()


#3

use the write option when opening the file. The file doesn't exist yet.


#4

I'm sorry I am new at this, how do I use the write option to open the file?


#5

your code is working fine

see if writing to file works:

my_file = open("output.txt", "w")

otherwise refresh the page


#6

Haha thanks, it worked after I refreshed the page!


#7