mercredi 24 février 2016

How do I use writelines() correctly?

I would like to write random prime numbers in new lines to a text file, but when I run my script it writes all numbers in one line. It's very likely that I don't understand something correct, please help me.

There is my code:

import random
file = open("prime.txt", "w")
i=0
while(i<=100):
    temp=str(random.randint(1,500))
    file.writelines(temp)
    i+=1
file.close()




Aucun commentaire:

Enregistrer un commentaire