3. Writing


#1



https://www.codecademy.com/courses/python-intermediate-en-OGNHh/0/3?curriculum_id=4f89dab3d788890003000096#

I get the correct output but I do not understand why we do my_file.write("%s\n" % (item))
. I get the my_file.write part, but i do not get why we put "%s\n" % (item) inside the parentheses. Thanks for any help.

my_list = [i**2 for i in range(1,11)]
my_file = open("output.txt", "r+")

for item in my_list:
    my_file.write("%s\n" % (item))
my_file.close()


#2

Have you considered what the % operator is doing in that expression? This is something that earlier exercises have mentioned so I can't tell if that's what you're unsure about? (be specific about the problem) And if so you might even know where to look. If not, then you appear to need a bit of help with how to look up that information, it isn't necessarily very easy to figure out a good search query for it.


#3

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