Why isn’t the lesson accepting what I write to the file?
Answer
Be sure not to add any additional spaces or punctuation or unnecessary text to the output file since Codecademy checks for exactly what is asked for. A common error is using string formatting and putting a space between the current for loop variable being written and the newline character, \n.
To fix this, simply remove any spacing you wrote and just write() the current number and the newline character directly afterward.
When I use that code, it works perfect, but is not accepted by the lesson. When I change my code to match the solution’s recommended code, my console registers an error and the lesson doesn’t accept it either. Is there a bug?
If this is a tab open in the codecademy learning environment then it won’t be updated automatically when the file is altered in the background. Try closing and reopening that tab once you have run your script to view any changes made.
Thanks @tgrtim,
I advanced onto the next topic in the section and then pressed the back button and the output.txt tab was populated. Just wanted to make sure that I was correctly writing to the output file even though I could see that the squared results were correct by using the print command.
Yes, I believe it’s a bug. I know because, after checking the solution, I had typed exactly what was written there and it still would not accept it. However, when I clicked “Replace with Solution” it automatically gave me the green light.