密码要求:函数
1.长度超过8位spa
2.包括大小写字母.数字.其它符号,以上四种至少三种3d
3.不能有相同长度超2的子串重复code
说明:长度超过2的子串blog
一组或多组长度超过2的子符串。每组占一行input
若是符合要求输出:OK,不然输出NGit
021Abc9000 021Abc9Abc1 021ABC9000 021$bc9000
OK NG NG OK
def fun1(str): if len(str) > 8: return 1 else: return 0 def fun2(str): num1 = 0 num2 = 0 num3 = 0 num4 = 0 for i in str: if 'a'<=i and i<='z': num1 = 1 elif 'A' <=i and i<='Z': num2 = 1 elif '0' <=i and i<='9': num3 = 1 else: num4 = 1 if (num1+num2+num3+num4) >=3: return 1 else: return 0 def fun3(str): for i in range((len(str)-3)): if str[i:i+3] in str[i+1:]: return 0 break return 1 while True: try: str1 = input() if fun1(str1) and fun2(str1) and fun3(str1): print('OK') else: print('NG') except: break
思路:将每一个条件单独考虑,写成一个个函数。不定多少组输入时,用while循环。io