3. Writing


#1



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

The code below works, but I got this error message in the console:

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

What's causing it?


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

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

# Add your code below!
for v in my_list:
    my_file.write(str(v))
    my_file.write("/n")
my_file.close()


#2

I get the same error, I am fairly certain it is a bug since that portion of the code is already there when you start the lesson.


#3

use this: my_file.write("%s\n" % (v))


#4

I already found a workaround, but thanks anyway!


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.