Skip to content

Instantly share code, notes, and snippets.

@Alexandr6363
Last active May 14, 2022 07:20
Show Gist options
  • Save Alexandr6363/4d2948fd0b1f77c132e540343e6192ad to your computer and use it in GitHub Desktop.
Save Alexandr6363/4d2948fd0b1f77c132e540343e6192ad to your computer and use it in GitHub Desktop.
Easy password generator in Python with iteration next/yield
from string import ascii_lowercase, ascii_uppercase
import random
chars = ascii_lowercase + ascii_uppercase + "0123456789!?@#$*"
n = int(input("Enter password length: "))
m = int(input("Enter how many passwords to generate: "))
def gen_char_password(n):
for i in range(n * m):
index = random.randint(0, len(chars) - 1)
yield chars[index]
gen = gen_char_password(n)
for i in range(m):
for i in range(n):
print(next(gen), end='')
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment