#! /usr/bin/env python import string import secrets def create_password(long=int(10), sonder="!#$%&()*+-/:;<=>?@[]_{|}"): print("Sonderzeichen:", sonder) alle = string.ascii_letters + string.digits + sonder while True: tx = "" anz = [0, 0, 0, 0] for i in range(long): zeichen = secrets.choice(alle) tx += zeichen if zeichen in string.ascii_lowercase: anz[0] += 1 elif zeichen in string.ascii_uppercase: anz[1] += 1 elif zeichen in string.digits: anz[2] += 1 else: anz[3] += 1 # print("Anzahl:", anz) if 0 not in anz: break return tx if __name__ == "__main__": print(create_password(long=20))