0
what wrong with this program?
Task: Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special characters ('!', '@', '#', '
#x27;, '%', '&', '*'), and a length of at least 7 characters. If the password passes the check, output 'Strong', else output 'Weak'. another explanation: Explanation: The password has 2 numbers, 2 of the defined special characters, and its length is 14, making it valid. my program : password = input() nums = "1, 2, 3, 4, 5, 6, 7, 8, 9" sc = "!, @, #, $, %, &, *" lets = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" if password in nums >= 2 and password in sc >= 2: if password in lets >= 7: print("Strong") else: print("Weak")1 Respuesta
+ 5
- those commas in the strings are characters too
nums = "0123456789"
- same for special characters.
sc = "!@#$%&*"
password = input().lower()
Makes all letters lowercase, even if you have nonletter char in the string.
so,
lets = "abcdefghijklmnopqrstuvwxyz"
"if nums in password :" and not otherwise, but "in" just checks for num, as in a set. It doesn't do counting.
what you can do is introduce a counter for each kind of character, then start a loop, iterate over password, increase count under given conditions.
There are various ways you can do this but I guess the above bit is the natural continuation of your code. (please try it first)
https://code.sololearn.com/cSBD0mEvWYJ6/?ref=app