def check_password(password): if len(password) < 8: return False has_upper = False has_lower = False has_digit = False for char in password: if char.isupper(): has_upper = True elif char.islower(): has_lower = True elif char.isdigit(): has_digit = True return has_upper and has_lower and has_digit

example usage

print(check_password("Password123")) # True print(check_password("weakpass")) # False

编写函数验证密码是否符合要求。规则:密码包含至少8个字符至少一个大写字母和一个小写字母至少一个数字。符合返回True否则返回False。python编写

原文地址: https://www.cveoy.top/t/topic/fK8j 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录