Answer the question
In order to leave comments, you need to log in
Why does the infinite loop work?
def passwd(length: int, difficult: int) -> List:
# импортируем модуль для генерации случайных чисел
import random
# создаем кортежи из букв, символов и цифр
chars: tuple = ('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')
symbols: tuple = ('@', '$', '?', '#', '&')
nums: tuple = tuple(range(10))
# создаем пароль в зависимости от уровня сложности
parole = []
if difficult == 1:
while len(parole) != length: # length - длина пароля
i = random.randrange(len(chars) - 1) # диапазон кортежа - 1
parole.append(chars[i])
parole.append(chars[i].upper()) # если убрать эту строку, то цикл работает верно
return parole
print(passwd(3, 1))
Answer the question
In order to leave comments, you need to log in
If you add two characters at a time, you will never catch an odd password length.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question