主要就是输入判断检测,以及一些正则的学习。刚开始玩python项目,代码写的不好。我以前玩C的!!
代码的价值与其是否能够实现功能等价!
#密码输入检测 密码长度不少于8个字符,而且必须包含大写/小写/数字 import re def inputPasswordCheck(strInput): strInput = input() #长度判断 if len(strInput) != 8: print('len error') return #表达式匹配 小写字母 PasswordCheck = re.compile(r'[a-z]') mo = PasswordCheck.search(strInput) if mo == None: print('search a-z error') return #表达式匹配 数字 PasswordCheck = re.compile(r'[0-9]') mo = PasswordCheck.search(strInput) if mo == None: print('search 1-9 error') return #表达式匹配 大写字母 PasswordCheck = re.compile(r'[A-Z]') mo = PasswordCheck.search(strInput) if mo == None: print('search A-Z error') return return strInput if __name__== '__main__': strInput = '' i = 0 print('please input a password:') try: while True: reGet = inputPasswordCheck(strInput) i = i+1
#如果输入成功则打印 if reGet != None: print(reGet) #如果输入次数大于5次退出 if i >5 : print('try time enouth the demo exit') break except KeyboardInterrupt: print('the demo exit')