Simple Password Generator in Python

Simple Password Generator in Python

Here is the simple Password generator in Python.

# Password generator.

import random
password = ""
# Ask for password length.
pass_length = int(
    input("Enter password length: \n")
    )

for i in range(pass_length):
    num = random.randint(33, 126) 
    # ASCII Characters.
    
    password += (chr(num))

print(f"Password: {password})

Output:

Enter password length: 9 
%O&W{V5/z

Code explanation:

  • Import the random module.
  • Take the password length as an input.
  • Define the empty password string.
  • Use for-loop to generate the password for a specific length.
  • Use a random module to create a number from 33 to 126 , which is nothing but the ASCII characters.
  • Convert the ASCII characters into characters and append that to the password.
  • Print the password.

You can also watch the demo here.

This is all about Simple Password Generator in Python. Keep automating the boring stuff.

For more such important Python tips and tricks follow us on YouTube.

Happy Pythoning!

Leave a Reply

Your email address will not be published. Required fields are marked *