密码题
sym = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''letter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
nums = '0123456789'
passwd=input('please,enter your password : ')
safty=0
comp=0
def length():
global passwd
global safty
if 0<len(passwd)<=8:
safty=1
elif 8<len(passwd)<=16:
safty=2
elif 16<len(passwd)<=20:
safty=3
elif 20<len(passwd):
safty=0
def complexity():
global passwd
global comp
for each in passwd:
if each in nums:
comp+=1
break
for each in passwd:
if each in letter:
comp+=1
break
for each in passwd:
if each in sym:
comp+=1
break
def judge():
global passwd
global comp
if safty==1 and comp==1:
print('password is not safe.')
if safty==3 and comp==3:
print("password is safest")
else:
print('your password is safe.')
length()
while safty==0:
passwd=input('please,enter passwoed,and length less than 20 :')
length()
complexity()
judge()
print(safty,comp)
密码题,我在改成函数的时候发现
please,enter your password : 899763sssdgh!!!@#$$
password is safest
3 3
please,enter your password : (此处为只有空格,在执行while ==0语句)
please,enter passwoed,and length less than 20 :899763sssdgh!!!@#$$
password is safest
3 3
safe和 safest都能打出,但not safe出问题了,为什么它会再打句safe啊?????明明2个都是1啊
please,enter your password : 34645
password is not safe.
your password is safe.
1 1
回车重新输入也是这个问题
please,enter your password :
please,enter passwoed,and length less than 20 :34666
password is not safe.
your password is saft.
1 1 def judge():
global passwd
global comp
if safty==1 and comp==1:
print('password is not safe.')
elif safty==3 and comp==3:
print("password is safest")
else:
print('your password is safe.') 把第二个 if 改成 elif
页:
[1]