import re print('\033[1;32;1m') print('请输入密码:\n1. 不得少于8个字符\n2.只能包含大小写字母,数字和下划线\n3.大写字母,小写字母和数字至少要包含两种') print('\033[0m') while True: password=input('请输入:') if len(password) < 8: print('输入错误!(不得少于8个字符),请重新输入!') else: word=re.search('[\w_]+',password) if word.group()==password: a=b=c=int(0) if re.findall('[a-z]',password) : a=1 if re.findall('[A-Z]',password): b=1 if re.findall('[\d]',password): c=1 if a+b+c>=2: print('密码正确!程序结束!') exit() else: print('密码有误,重新输入!') else: print('2密码有误,重新输入!')