import random
#Importing random will randomize the characters in the library.
import string
#Importing string represents the character set.
#These will be used later on to create our randomized password, but we have to import them first.
from os import system
#This function defines the system/window/host for the program.
superString = ("string.ascii_letters+string.digits+string.punctuation")
#This is the library we're using.
#The library includes ascii letters.
#The library also includes ascii numbers.
#The library also includes ascii symbols.
#The library does NOT consist of spaces or return carriages.
#These are the characters that will be used in our randomized password.
def programExit():
#This is the function that leaves the program once you're finished with it.
exitAnswer = input("Would you like another password? (y/n)")
#We're printing the question to see if the user is done with the program or not.
if exitAnswer == "y":
#If the user is NOT done with the program (or submit y for yes)...
password()
#We rerun the program.
elif exitAnswer == "n":
#If the user is done with the program (or submit n for no)...
print("Goodbye!")
#We leave the program and say goodbye to the user
else:
#If the user submits anything else to the question...
programExit()
#We can't recognize what they said, so we exit the program.
def password():
userPassword = ""
#Here is the actual password function.
system("clear")
#When using the program, the window will automatically clear the way for the function.
print("Welcome to my random password generator!")
#Hello to everyone who uses my script!
print()
#Print a blank line, or a break.
print("How many characters would you like for your password?")
#Ask the user how many characters they would like for their password, which will be used later in the
#passwordLength method.
passwordLength = int(input("==>"))
#Where the user will type in how many characters they want the password to be and defined passwordLength.
system("clear")
#The window will clear the way for the answer again.
for password in range(passwordLength):
#Here, we are defining the length of the password. The length is determined by a question to follow.
characterUsed = random.choice(superString)
#The characterUsed function randomizes the superString function.
userPassword += characterUsed
#userPassword is the length of the passwordLength function and the element of random in the characterUsed function
#combined.
print (userPassword)
#This function will either leave the program, or make another password, according to what the user wants.
programExit()
#Either leave hte program or ask for another password.
if __name__ == "__main__":
password()
Welcome to my random password generator! How many characters would you like for your password? ==>5 snisp Would you like another password? (y/n)n Goodbye!