密碼要求:函數
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