mardi 5 mai 2020

How can I fix python printing unnecessary "in range" information

I want to make a advanced password generator. And I want to add a feature where each password is saved in a text file. But at the last part where it generates another password, Python prints each character step by step this causes to save each character! My computer crashed 3 times today because of this bug. Sorry for all the bad grammar or bad explanation.

Anyways here is my code:

import random

Alphabet = "abcdefghilmnopqrstuvwxyzABCDEFGHILMNOPQRSTUVWXYZ123456789()]\%$*@!><?"
FileAlphabet = "abcdefghilmnopqrstuvwxyz"
number = input("Number of passwords? ")
number = int(number)

length = input("Password length? ")
length = int(length)



for p in range(number):
    password = ''
    for c in range(length):
        password += random.choice(Alphabet)


print(password)


text = password

saveFile = open("MOST_RECENT_PASSWORD.txt", 'w')
saveFile.write(text)
saveFile.close()

new = input("Generate another password? yes/no" )
FileName = ''

if new == "yes":
    for pwd in range(number):
        password = ''
        for c in range(length):
            password += random.choice(Alphabet)
            FileName += random.choice(FileAlphabet)
            password += random.choice(Alphabet)
            print(password)
            saveFile = open(FileName + ".txt", 'w')
            saveFile.write(text)
            saveFile.close()



Aucun commentaire:

Enregistrer un commentaire