Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import random
- #get user input as to how long they want the password
- passwordlen = int(input("How long would you like your password to be? : "))
- #our chars
- chars = "abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*"
- charlist = []
- #couldn't figure out the split() function so I just did it with a for loop
- for x in chars:
- charlist.append(x)
- #define password list; we can splice this back together once we are done appending
- password = []
- for x in range(0, passwordlen):
- #this picks a random character from the charlist
- ch = math.floor(random.randint(0, len(chars)))
- #append the chosen character
- password.append(charlist[ch])
- #join the password list
- print(''.join(password))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement