网站记录:https://py.checkio.org/mission/house-password/solve/
问题:判读输入的密码是否符合要求:超过10位,英文加数字,大小写,没有特殊符号
我的代码:
import re
def checklen(data):
return len(data) >= 10
def checkUpper(data):
upper = re.compile('[A-Z]+')
match = upper.findall(data)
if match:
return True
else:
return False
def checkLower(data):
lower = re.compile('[a-z]+')
match = lower.findall(data)
if match:
return True
else:
return False
def checkNum(data):
num = re.compile('[0-9]+')
match = num.findall(data)
if match:
return True
else:
return False
def checkSymbol(data):
symbol = re.compile('([^a-zA-Z0-9])+')
match = symbol.findall(data)
if match:
return True
else:
return False
def checkio(data):
if checklen(data):
if checkUpper(data):
if checkLower(data):
if checkNum(data):
return True
else:
return False
else:
return False
else:
return False
else:
return False
if __name__ == '__main__':
大神的代码:(代码来自:https://py.checkio.org/mission/house-password/publications/Renelvon/python-3/first/?ordering=most_voted&filtering=choice 作者:Renelvon)
def checkio(s):
fs = ''.join(filter(str.isalnum, s)) # keep only letters and digits
return (
len(fs) >= 1 # There is at least one letter or digit
and len(s) >= 10 # ... and there are at least 10 characters
and not fs.isalpha() # ... and there is at least one digit
and not fs.isdigit() # ... and there is at least one letter
and not fs.islower() # ... and not all letters are lowercase
and not fs.isupper() # ... and not all letters are uppercase
)
大神二(Riddick)
import re
def checkio(data):
return True if re.search("^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$", data) and len(data) >= 10 else False
if __name__ == '__main__':