In this post, we will create a simple password generator in Python by taking input from the user with a detailed explanation and example.

But before we jump into the algorithms or programming part few programming concepts you must know:

## Algorithm

1. Import `random` module
2. Create three lists, The first one contains a list of alphabets (upper or lowercase both), the second list contains a list of numbers from 0 to 9 and the third one contains a list of special characters such as @, #, \$, ^, &, *, etc
3. Take user input such as how many characters, numbers, and special characters they want in their password.
4. Create an empty list to store your password (`password_list = []`).
5. Using `for-loop` iterate over user input times in each list and randomly choose characters, numbers, and special characters and append it in empty list `password_list`
6. After that join your `password_list` list into the string using the `join()` method.

From the above algorithms, now we know how we will implement a password generator in Python. So let’s start writing code for it.

## Source Code

``````import random

alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

numbers =[0,1,2,3,4,5,6,7,8,9]

special_characters = ['!','@','#','\$','%','^','&','*','(',')','_','-','+','=']

special_char = int(input('How many special characters you want : '))

ch = random.choice(alphabets)
num = str(random.choice(number)) # choice method choose random item from list
for l in range(1,special_char+1):
sp = random.choice(special_character)

## Output-1

``````How many alphabats you want in your password : 4
``````How many alphabats you want in your password : 5