题解 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
def checkifTrue(s):
if len(s) <=8:
return False
big_alpha = 0
small_alpha = 0
number = 0
others = 0
for i in s:
if i.isdigit():
number = 1
elif i.isupper():
big_alpha = 1
elif i.islower():
small_alpha = 1
elif i.isspace():
others = 0
else:
others = 1
x =[big_alpha,small_alpha,number,others]
if sum(x)<3:
return False
## the length
for i in range(len(s)-3):
sub_str = s[i:i+3]
if len(s.split(sub_str))>=3:
return False
else:
return True
while True:
try:
print('OK' if checkifTrue(input()) else 'NG')
except:
break
这一题发现自己对 return, continue, break 这一块知识点不熟悉:
break: 常用于while,loop循环,用来终止整个循环。如果if 后面添加的是break, 整个while True 的循环都会终止;如果在while里面嵌套的for循环里使用,那么跳出当前循环。
continue: 后面的不运行,但是不会终止while True 的循环
return:和continue相似