mardi 2 novembre 2021

why do I get error on file write with python? [duplicate]

I want the code to write 100 random files from 1 to 9999999999 in a file called users.txt but it always only writes two lines, one of them a random number, one of them blank. Code:

import random
wrote = 0
while True:
    if wrote == 100:
        print("writing finished!")
        break
    else:
        with open('users.txt', 'w') as f:
            f.write(str(random.randint(1, 9999999999)) + '\n')
        wrote = wrote + 1

some random result I get: 3218450110 what is wrong?




Aucun commentaire:

Enregistrer un commentaire