Lesson 3 Pl Help where is the error in my code


Below is my code.

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

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

Add your code below!
for item in list:
my_file.write(str(item) + "\n")


Can you post both the link to the exercise and the error you are getting?


The error in the console is "syntax error invalid syntax"


Okay there are a couple of issues with your code.

Firstly the line "Add your code below!" needs to be either deleted or commented out.

Secondly, you've not indented your for loop on the second to last line.


for item in list:
You need to indent the lines below
my_file.write(str(item) + "\n")

also your writing the value of i and not the value of my_list at the i indices.
so its

my_file.write(str(my_file[item]) + "\n")


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