3. Writing- code passes, but I get an error


This is my code, which passes, but nothing gets printed and this is the error message I get:

Traceback (most recent call last):
File "python", line 3, in
IOError: [Errno 2] No such file or directory: 'output.txt'

my_list = [i**2 for i in range(1,11)]

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

for i in my_list:


Try this

my_file.write(str(i) + "\n")


Makes no difference- I get the same error


I had that error, think it's some kind of bug. Type something inside output.txt and it should work.


It seems to be a bug. Before you run the code, click on the output.txt tab and then on the first entry. Press return a few times. You can now run your code.

I guess this prompts the system into creating the output file ready for you to write to it


this worked for me:
my_file.write(str(my_list[i])+ "\n")


Try to change the range in the first line to 1 through 12:

my_list = [i**2 for i in range(1,12)]

and in your for loop:

my_file.write(str(i) + "\n")


If you change the open to w and not r+, it works

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


I followed the instruction as is and works!!

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

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

for c in my_list:




my_list= [i**2 for i in range(1,11)]
my_file = open("output.txt", "r+")
it should be:

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

snd so is the below