Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # imports random module from the library
- import random
- # create a list of possible characters
- characters = ["1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
- # define a function to generate a password
- def generate_password(pwd_length):
- # sets up an empty list to store the password that will be created
- password = []
- # set up a for loop to iterate for how many characters are needed in the password
- for x in range (pwd_length):
- # select a random item from the characters list
- newItem = random.choice(characters)
- # add that item to the password list
- password.append(newItem)
- # return all the new items in the password list joined together in one string
- return ''.join(password)
- # ask the user to specify the length of their password
- psw_length = int(input("Please enter the length of your password "))
- # set the password from the output of the generate_password function
- password = generate_password(psw_length)
- # output the generated password
- print (password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement