93.9k views
5 votes
Write a short program that uses a for loop to write the numbers 1 through 10 to a file

User Rainey
by
8.0k points

1 Answer

5 votes
An example would be as follows:

outfile = open('filename.txt', 'w')
for num in range (1, 11):
outfile.write(str(num) + '\\')
outfile.close()

And a second example:

dataFile = open("filename", "w")
for line in range(11):
dataFile.write("%s\\" % line)
dataFile.close()


Hope this helps.
User Mgraham
by
8.6k points

No related questions found