Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import string
- def generate_password(length=12):
- characters = string.ascii_letters + string.digits + string.punctuation
- password = ''.join(random.choice(characters) for _ in range(length))
- return password
- def main():
- print("Welcome to the Password Generator!")
- while True:
- try:
- password_length = int(input("Enter the desired password length (at least 4 characters): "))
- if password_length < 4:
- print("Password length should be at least 4 characters.")
- continue
- password = generate_password(password_length)
- print("Generated password:", password)
- break
- except ValueError:
- print("Please enter a valid number for the password length.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement