Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import math
  2. import random
  3.  
  4. #get user input as to how long they want the password
  5. passwordlen = int(input("How long would you like your password to be? : "))
  6.  
  7. #our chars
  8. chars = "abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*"
  9.  
  10. charlist = []
  11.  
  12. #couldn't figure out the split() function so I just did it with a for loop
  13. for x in chars:
  14. charlist.append(x)
  15.  
  16. #define password list; we can splice this back together once we are done appending
  17. password = []
  18.  
  19.  
  20. for x in range(0, passwordlen):
  21. #this picks a random character from the charlist
  22. ch = math.floor(random.randint(0, len(chars)))
  23. #append the chosen character
  24. password.append(charlist[ch])
  25.  
  26. #join the password list
  27. print(''.join(password))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement