+ 1

Code coach - Password validation

I think the object of this quiz is count to find how many specific characters are in the input. I solved it but i think there are better ways because if there are thousands of characters to find, my way will take a day or more. If there are better ways to count something in string or to shorten my code, please let me know. Here is my code p=input() count_num=p.count('0')+p.count('1')+p.count('2')+p.count('3')+p.count('4')+p.count('5')+p.count('6')+p.count('7')+p.count('8')+p.count('9') count_chr=p.count('!')+p.count('@')+p.count('#')+p.count('%')+p.count('&')+p.count('*')+p.count('

#x27;) if count_num >=2 and count_chr >=2 and len(p)>=7: print('Strong') else: print('Weak')

14th Mar 2021, 7:50 AM
Seung won LEE
Seung won LEE - avatar
6 Antworten
+ 2
Try my solution: symbols = ['!', '@', '#', '
#x27;, '%', '&', '*'] numbers = ['0','1','2','3','4','5','6','7','8','9'] i = str(input()) s = sum(1 for j in i if j in symbols) n = sum(1 for j in i if j in numbers) if len(i) >= 7 and s >= 2 and n >= 2: print('Strong') else: print('Weak')
14th Mar 2021, 8:15 AM
Tomas Konecny
+ 2
There are many ways to resolve this challenge. You could create separate filters for nums & specials for example, then compare the input against the filters - increasing the count of the item as it appears. Add in the length of the password and you have everything you need to determine the output
14th Mar 2021, 8:16 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Tomáš Konečný you imported numpy but never used it!
14th Mar 2021, 8:41 AM
Abhay
Abhay - avatar
0
Thanks a lot guys.
14th Mar 2021, 8:26 AM
Seung won LEE
Seung won LEE - avatar
0
Thanks for noticing 😆
14th Mar 2021, 9:28 AM
Tomas Konecny
0
There is another approach digits = "0123456789" symbols = "@#₹_&-+/" lettercount = 0 symbolcount = 0 password = input() for lt in password: if lt in digits: lettercount += 1 elif lt in symbols: symbolcount += 1 if symbolcount > 2 and lettercount > 6: print("Strong") else: print("Weak") DHANANJAY
15th Mar 2021, 8:48 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar