Python有关字符串的问题,Rule2的循环不知道怎么写:

Python有关字符串的问题,Rule2的循环不知道怎么写:

img

可以用正则表达式或者直接遍历一个个判断。

def checkPasswd(passwd):
  n1=0
  n2=0
  n3=0
  if len(passwd)<8:
    return False
  for c in passwd:
    if c.isdigit():
      n1=n1+1
    elif c.isupper():
      n2=n2+1
    elif c.islower():
      n3=n3+1
    else:
      return False
  if n1>0 and n2>0 and n3>0:
    return True
  else:
    return False


print(checkPasswd("aA12331222"))
print(checkPasswd("aA123"))
print(checkPasswd("bbb1212121"))
print(checkPasswd("AAaa123***"))
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632