Can not find the mistake in logical operators, may be someone can give me a hint how to put AND OR OR.
Problem is with if data and data and data and (or or or)
in () > I need to accept code: contains capital letters, then the number of capitals must be odd have at least 4 letters (independent of case) so it means: UPPER LOWER >= 4 or UPPER >= 4 or LOWER >= 4
output should be:
checker_code("Dfgh#88$")
True
def checker_code(security_code):
data = {'upper':0, 'lower':0, 'spec':0, 'digit':0, 'sum':0}
spec_charact = ['!','@','#','$','%','^','&','*','(',')','?',',','.']
if len(security_code) < 8 or len(security_code) > 30:
return False
for i in security_code:
if any(i.isupper() for i in security_code):
data['upper'] = data['upper'] 1
if i.islower():
data['lower'] = data['lower'] 1
if i in spec_charact:
data['spec'] = data['spec'] 1
if i.isdigit():
data['digit'] = data['digit'] 1
if i.isdigit():
data['sum'] = data['sum'] int(i)
if(data['upper'] % 2 !=0 and data['spec'] >= 2 and data['digit'] >= 2 and data['sum'] % 2 == 0 and (data['upper'] data['lower'] >= 4 or data['upper'] >= 4 or case['lower'] >= 4)):
return True
else:
return False
CodePudding user response:
Change your line
if any(i.isupper() for i in security_code):
to this:
if i.isupper():
Since you are already iterating for i in security_code
in your outer for loop, it is redundant to do it again in your first if-statement. I think your code is applying whether the 1st character is upper across all letters, so it thinks your string of 8 characters has 8 upper-case characters since "D" is uppercase
CodePudding user response:
Your test if any(i.isupper() for i in security_code):
is adding to data["upper"]
everytime through the loop because you are checking all of security_code
at every iteration and since it does have a uppercase letter, it adds to the count.
Instead, just do if i.issuper():
to only check the current element of the security code.