Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import string
- import sys
- possible_chars = string.ascii_letters + string.digits + string.punctuation
- def nextchar(chars):
- return random.choice(chars)
- yes_or_no = input("""
- Would you like a random password suggestion generated?
- Type Yes to continue: """).lower()
- if yes_or_no == 'yes':
- try:
- pwd_len = int(input('How long do you want your password? '))
- except ValueError:
- sys.exit("You need to enter an integer. Please start the program over.")
- if 0 < pwd_len:
- new_pwd = ""
- for _ in range(pwd_len):
- new_pwd += nextchar(possible_chars)
- print("Your new password is:\n" + new_pwd)
- else:
- print("I can only generate passwords between 1 and 25 characters long.")
- else:
- print("Well then, why did you run me?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement