Last active
May 14, 2022 07:20
-
-
Save Alexandr6363/4d2948fd0b1f77c132e540343e6192ad to your computer and use it in GitHub Desktop.
Easy password generator in Python with iteration next/yield
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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