+ 1
Working with files filling up with numbers
WoNT WORK DESCRIPTION: Take a number N as input and write the numbers 1 to N to the file "numbers.txt", each number on a separate line. Sample Input: 4 Sample Output: 1 2 3 4 The given code reads the content of the file and outputs it.
6 Respuestas
+ 10
n = int(input())
file = open("numbers.txt", "w+")
#your code goes here
for line in range(1, n+1):
file.write(str(line)+"\n")
file.close()
f = open("numbers.txt", "r")
print(f.read())
f.close()
This is also works ....
+ 2
This is my answer.
n = int(input())
i = 1
file = open("numbers.txt", "w+")
#your code goes here
while i <= n:
file.write(str(i) + "\n")
i += 1
file.close()
f = open("numbers.txt", "r")
print(f.read())
f.close()
0
n = int(input())
file = open("numbers.txt", "w+")
#your code goes here
for line in range(1, n+1):
file.write(str(line)+"\n")
file.close()
f = open("numbers.txt", "r")
print(f.read())
f.close()
0
n = int(input())
file = open("numbers.txt", "w+")
#my code is here
for i in range(n):
file.write(str(i+1)+"\n")
print("\n")
file.close()
f = open("numbers.txt", "r")
print(f.read())
f.close()
0
with open("numbers.txt", "w") as file:
for i in range(1, 10000001):
file.write(f"{i}\n")
- 1
not sure how to complete it
n = int(input())
file = open("numbers.txt", "w+")
#your code goes here
f = open("numbers.txt", "r")
print(f.read())
f.close()