Writing


#1



I am currently stuck on WRITING, Under File Input/Output, Python.


My code exactly is:


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) + "\n")
my_file.close()



It then reads:
"Oops, try again. It looks like your file doesn't contain each element from my_list on its own line."



#2

As your code is not formatted It's hard to tell what's the problem,
But Its surely looks "wrong indentation" ,
Check indentation of program.
check your last line of program,make sure that its a separate block of code and It should have same indentation level as for loop.

if code is correct,refresh and submit again!


#3

Thank you my friend, Extremely helpful. Was stuck on that section for close to an hour.
Kind regards,
BAGATOV, Azamat.


#4

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