3/12 File Input/Output



When run it produces this error.
Oops, try again. It looks like your file doesn't contain each element from my_list on its own line.

Expected this code to execute, but the output.txt is empty.

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

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

# Add your code below!
for i in my_list:


Turns out the bit the code academy people put in is wrong.
my_file = open("output.txt", "r+")
my_file = open("output.txt", "w+")


Try setting i to a string before you place it in the write function.


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