Step 1: Import the required modules.
import random import string
Step 2: Input the length of password
length =int(input("\n Enter the length of password")
Step 3: Define the variable.
string.printable : A combination of string.digits, string.ascii_letters, string.punctuation and string.whitespace.
0123456789ABCDEFGHIJKLMNOPRSTUVWXYZabcdefghijklmnopqrstuvwxyz~`!@#$%^&*()_+/*-.:;”\|’?/><}{[] etc
symbols = string.printable
Step 4: Combine the data.
all = symbols
Step 5: Use random
temp = random.sample(all, length)
Step 6:Create the password.
password = "".join(temp)
Step 7: Print the password.
print(password)
Example :-
import random import string print("Welcome to Password Generator") length = int(input("\n Enter the length of password: ") symbols=string.printable all = symbols temp = random.sample(all, length) password = "".join(temp) print(Password)
Output :
Welcome to Password Generator
Enter the length of password : 8
5Q2~&cC