I am fairly new to python. I want to create a program that can generate random numbers and write them to a file, but I am curious to as whether it is possible to write the output to a .txt
file, but in individual lists. (every time the program executes the script, it creates a new list)
Here is my code so far:
def main():
import random
data = open("Random.txt", "w" )
for i in range(int(input('How many random numbers?: '))):
line = str(random.randint(1, 1000))
data.write(line + '\n')
print(line)
data.close()
print('data has been written')
main()
Aucun commentaire:
Enregistrer un commentaire