Writing


#1



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


it makes claim that the values are not printed on their own lines, but the prompt shows otherwise.
1
4
9
16
25
36
49
64
81
100
.textoutput.textoutput.textoutput.textoutput.textoutput.textoutput.textoutput.text


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

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

for item in my_list:
    my_file.write("%s\n" % (item))

my_file.close()


#2

Open the text file in write mode, like so:

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


#3

Thank you, that's counter to what the instructions say but that works and it makes more sense.


#4

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