输入一个字符串,判断该字符串是否可以作为密码。可作为密码的条件:必须是包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间。
以下代码,仅为抛砖引玉:
tmp = set()
result = "不符合"
flag = "123"
if a.isalnum() and 8 <= len(a) <= 10:
    for x in a:
        if x.isdigit():
            tmp.add("1")
        elif x.islower():
            tmp.add("2")
        elif x.isupper():
            tmp.add("3")
    if sorted(flag) == sorted("".join(tmp)):
        result = "符合"
print(result)原文:https://blog.51cto.com/14730644/2473302