Writing


#1



Exercise: Writing
I'm pretty sure my code is correct (at least it looks the same as other ones on the q&a board) . The compiler throws an error anyway:


Error message:
File "python", line 9
my_file.close()
^
SyntaxError: invalid syntax


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

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

# Add your code below!
for item in my_list:
    my_file.write("%s\n" % str(item))

my_file.close()


#2

Okay, sorry, I was to fast asking for help. Found out accidently converted item to a string twice.


#3

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