密碼通常包含大小寫字母、數字和特殊字符。給定一個密碼(字串),請撰寫一程式,每項
合格得1 分,總分為5 分,檢查密碼規則如下:
1. 密碼長度至少要有八個字元(含)以上;
2. 至少要有一個數字;
3. 至少要有一個大寫英文字母;
4. 至少要有一個小寫英文字母;
5. 至少要有一個特殊字符[ ! @ # $ ˆ & * ( ) , . ? ” : { } | < > ]
def t0(chkstr):
# Use a breakpoint in the code line below to debug your script.
t=0
if (len(chkstr) > 8 ):
t=1
return t
def t1(chkstr):
# Use a breakpoint in the code line below to debug your script.
t=0
for i in chkstr:
if i in "0123456789":
t=1
break
return t
def t2(chkstr):
# Use a breakpoint in the code line below to debug your script.
t=0
for i in chkstr:
if i in "abcdefghijklmnopqrstuvwxyz":
t=1
break
return t
def t3(chkstr):
# Use a breakpoint in the code line below to debug your script.
t=0
for i in chkstr:
if i in "abcdefghijklmnopqrstuvwxyz".upper():
t=1
break
return t
def t4(chkstr):
# Use a breakpoint in the code line below to debug your script.
t=0
for i in chkstr:
if i in "" \
"!@#$^&*(),.?\":{}|<>":
t=1
break
return t
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
passstr='1234566'
print(t0(passstr)+t1(passstr)+t2(passstr)+t3(passstr)+t4(passstr))