Help me to check a password ! | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Help me to check a password !

It must contain at least two numbers and two of these symbols ['!', '@', '#', '

#x27;, '%', '&', '*'] , the length of a password must be at least - 7 This code does not works : x = input() nums = list(range(0, 10)) symb = ['!', '@', '#', '
#x27;, '%', '&', '*'] n = 0 s = 0 for i in symb :     if i in x :         s += 1 for i in nums :     if str(i) in x :         n += 1 if s >= 2 and n >= 2 and len(x) >= 7 :     print("Strong") else :     print("Weak")

17th Dec 2021, 3:02 PM
Abubakr Shomirsaidov
Abubakr Shomirsaidov - avatar
5 ответов
+ 1
# try this nums = list(map(str, range(0,10)))
17th Dec 2021, 3:45 PM
SoloProg
SoloProg - avatar
0
The problem is that a single number or symbol can be contained more than once
17th Dec 2021, 3:35 PM
Alexey Kopyshev
Alexey Kopyshev - avatar
0
How exactly does it not work? Do you get any errors? The results are wrong? If so, what is different from expected? Some hints: - There is a string method which checks if a character is a number, eliminating the need for a number list - for loops can iterate on characters of a string, so the symbol list doesn't need to be a list - "if <char> in <string> does inform presence, but not quantity, of said char, so the count will always be wrong for any repeated char. You could reverse the loop logic, iterating on input string instead of on the lists.
17th Dec 2021, 3:35 PM
Emerson Prado
Emerson Prado - avatar
0
Hi! Your problem is next: You try to check if symbol or number in password and you have to check if password character in symbols or numbers. Looks same, but let's imagine next situation: You have password #####11111 Length is 10, it's ok, but your code will output "Weak" because there is only 1 number and 1 symbol. You have to use next loop: for i in x: if i in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: n += 1 if i in ['!', '@', '#', '
#x27;, '%', '&', '*']: s += 1
17th Dec 2021, 3:38 PM
RaiRoko
RaiRoko - avatar
0
Oh , thanks It works now
17th Dec 2021, 3:40 PM
Abubakr Shomirsaidov
Abubakr Shomirsaidov - avatar