1) Write a program that stores the first 50 integers to a text file named numbers.txt. Each number should appear on a line all by itself.
Explanation:
here is the program which creates a file named file.txt in the write mode.
Then it uses a for loop, to write all the integers from 1 to 50 one by one to that file.txt.
Code:
f = open("file.txt", 'w')
for i in range(1, 51):
f.write(str(i)+"\n")
f.close()
output:
file.txt will get created with each of the integers from 1 to 50 on a separate line in the file.
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
Get Answers For Free
Most questions answered within 1 hours.