Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Importing the necessary modules!
- import random
- import string
- #Welcome
- print("Welcome to Password Generator!")
- #Forcing number input
- while True: # keep looping until we break out of the loop
- try:
- length = int(input("Please enter the desired length for your password: "))
- break # exit the loop if the previous line succeeded
- except ValueError:
- print("Please enter an number!") # loop back until input is a number
- # If program execution makes it here, we know that "length" is a number
- #define data
- lower = string.ascii_lowercase
- upper = string.ascii_uppercase
- num = string.digits
- symbols = string.punctuation
- #Combining the data
- all = lower + upper + num + symbols
- temp = random.sample(all,length)
- #Creating the password
- password = "".join(temp)
- #Printing the password
- print(password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement