I've made a password generator that works fine. It takes alphabetic, numeric, and punctuation characters and randomly generates a 8-16 character password.
import sys
import string
import random
def PasswordGenerator():
Name = input("What is your name? ")
if Name.isalpha():
GeneratePassword = input(Name + " would you like to generate a random password? ")
YesOptions = ["Yes", "yes", "Y", "y"]
NoOptions = ["No", "no", "N", "n"]
PasswordCharacters = string.ascii_letters + string.digits + string.punctuation
while GeneratePassword in YesOptions:
Password = "".join(random.choice(PasswordCharacters) for i in range(random.randint(8, 16)))
print(Password)
GeneratePasswordAgain = input("Would you like to generate another random password? ")
while GeneratePasswordAgain in YesOptions:
Password = "".join(random.choice(PasswordCharacters) for i in range(random.randint(8, 16)))
print(Password)
GeneratePasswordAgain = input("Would you like to generate another random password? ")
break
while GeneratePasswordAgain in NoOptions:
print("Good bye!")
sys.exit()
break
while GeneratePasswordAgain not in YesOptions or NoOptions:
print("Not a valid response! Try again.")
GeneratePasswordAgain = input("Would you like to generate another random password? ")
break
while GeneratePassword in NoOptions:
print("Good bye!")
sys.exit()
while GeneratePassword not in YesOptions or NoOptions:
print("Not a valid response! Try again.")
PasswordGenerator()
while GeneratePassword in YesOptions:
Password = "".join(random.choice(PasswordCharacters) for i in range(random.randint(8, 16)))
print(Password)
GeneratePasswordAgain = input("Would you like to generate another random password? ")
while GeneratePasswordAgain in YesOptions:
Password = "".join(random.choice(PasswordCharacters) for i in range(random.randint(8, 16)))
print(Password)
break
GeneratePasswordAgain = input("Would you like to generate another random password? ")
while GeneratePasswordAgain in NoOptions:
print("Good bye!")
sys.exit()
break
while GeneratePasswordAgain not in YesOptions or NoOptions:
print("Not a valid response! Try again.")
GeneratePasswordAgain = input("Would you like to generate another random password? ")
break
while GeneratePassword in NoOptions:
print("Good bye!")
sys.exit()
while Name is not Name.isalpha:
print("Not a valid response! Try again.")
PasswordGenerator()
PasswordGenerator()