I get extra numbers as the result


#1



for exercise number 3(writing) I write the code bellow :
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(str(item))
my_file.write("\n")

my_file.close()

and I get the eror : "it's look like you're file doesn't contain each element from my_list on its own line."
and as result it'll add the numbers below to my output.txt :
1
4
9
16
25
36
49
64
81
100
n81/n100/n 121]

I can't figure how does n81/n100/n121 generate?
the last line is my problem
I will appreciate any help here


Replace this line with your code.


#2

@alaleh-h,
Try it with

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

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

#Add your code below!

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

my_file.close()

#3

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