+ 2

Ive been trying and it won't work, can someone help?

Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify the file name and how many random numbers the file will hold. When I try to execute the code an error keeps popping up, Ive tried changing it several times and it won't work.. My code: import random afile = open("randomNumbers.txt", "w" ) for i in range(int(input("How many random numbers?: "))): line = str(random.randint(1, 100)) afile.write(line) print(line) afile.read() print("Enter the name of the file to which results should be written:", str(afile)) print("Enter the number of random numbers to be written to the file: ", line) print(afile.open()) afile.close()

31st Oct 2020, 9:33 PM
...
... - avatar
4 Respuestas
+ 1
I think if you write : with open("file name", "w") as afile: afile.write("........") .......
1st Nov 2020, 1:24 AM
Name
Name - avatar
+ 1
oOo, I'm sorry, Sir...
1st Nov 2020, 3:13 AM
Name
Name - avatar
0
@Jan Markus, Thank you!
31st Oct 2020, 11:42 PM
...
... - avatar
0
12.ba
1st Nov 2020, 6:16 PM
Leak Francisco
Leak Francisco - avatar