Ошибка по объявлению переменной
Пишу программу с графическим интерфейсом на python, пока занимаюсь кодом. При указании функции creatrPassword с атрибутами 20, True, True, True, False Вылетает ошибка, что переменная TTTT не объявлена. Хотя если вызвать эту же функцию с атрибутами 20, True, True, True, True, то ничего не происходит, пароль делается правильно и без ошибок. Вот код:
import random
# Пароль
letters = "abcdefghigklmnopqrstuvwxyz"
big_letters = "ANCDEFGHIGKLMNOPQRSTUVWXYZ"
numbers = "1234567890"
symbols = ":;.-_!?/,'*-&"
def createPassword(len, let, biglet, num, sym):
# len - показатель длины, принимаются параметры 6 - 20
# let - переключатель букв, принимаются значения True/False
# biglet - переключатель больших букв, принимаются значения True/False
# num - переключатель цифр, принимаются значения True/False
# sym - переключатель символов, принимаются значения True/False
# Система отправки сообщений (СОС)
if let and biglet and num and sym:
TTTT = True
elif let and biglet and num and not sym:
TTTF = True
elif let and biglet and not num and not sym:
TTFF = True
elif let and not biglet and not num and not sym:
TFFF = True
elif let and not biglet and not num and sym:
TFFT = True
elif let and biglet and not num and sym:
TTFT = True
elif let and not biglet and num and sym:
TFTT = True
elif let and not biglet and num and not sym:
TFTF = True
elif not let and not biglet and not num and not sym:
FFFF = True
elif not let and not biglet and not num and sym:
FFFT = True
elif not let and not biglet and num and sym:
FFTT = True
elif not let and biglet and num and sym:
FTTT = True
elif not let and biglet and num and not sym:
FTTF = True
elif not let and not biglet and num and not sym:
FFTF = True
elif not let and biglet and not num and not sym:
FTFF = True
elif not let and biglet and not num and sym:
FTFT = True
password_list = list()
if TTTT:
for i in range(len):
type = random.randint(0, 3)
if type == 0:
password_list.append(str(random.choice(letters)))
if type == 1:
password_list.append(str(random.choice(big_letters)))
if type == 2:
password_list.append(str(random.choice(numbers)))
if type == 3:
password_list.append(str(random.choice(symbols)))
print("".join(password_list))
elif TTTF:
for i in range(len):
type = random.randint(0, 2)
if type == 0:
password_list.append(str(random.choice(letters)))
if type == 1:
password_list.append(str(random.choice(big_letters)))
if type == 2:
password_list.append(str(random.choice(numbers)))
print("".join(password_list))
createPassword(20, True, True, True, False)
Источник: Stack Overflow на русском