Advertisement
HernandezGFX

Python Draft (P Gen)

Jan 22nd, 2022
1,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. #Importing the necessary modules!
  2. import random
  3. import string
  4.  
  5. #Welcome
  6. print("Welcome to Password Generator!")
  7.  
  8. #Forcing number input
  9. while True:      # keep looping until we break out of the loop
  10.     try:
  11.         length = int(input("Please enter the desired length for your password: "))
  12.         break    # exit the loop if the previous line succeeded
  13.     except ValueError:
  14.         print("Please enter an number!") # loop back until input is a number
  15.  
  16. # If program execution makes it here, we know that "length" is a number
  17. #define data
  18. lower = string.ascii_lowercase
  19. upper = string.ascii_uppercase
  20. num = string.digits
  21. symbols = string.punctuation
  22.  
  23. #Combining the data
  24. all = lower + upper + num + symbols
  25.  
  26. temp = random.sample(all,length)
  27.  
  28. #Creating the password
  29. password = "".join(temp)
  30.  
  31. #Printing the password
  32. print(password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement