我正在使用Python编写密码强度代码,想要判断我的密码(p
)是否包含数字。我已经知道如何通过p.isupper()
或p.islower()
来查看它是否包含大写或小写字母,并且我已经将它们放在一起了。我的朋友告诉我如何判断密码是否只包含数字,但现在我需要你的帮助。
running=True
while running:
p=raw_input("What is your Password? ")
if len(p) <6:
print "Your Password is too short"
if len(p) >12:
print "Your Password is too long"
if len(p) == 6 or 7 or 8 or 9 or 10 or 11 or 12:
print "Password Length OK"
running=False
print "Loop Broken" #this will be deleted, only for my help now
if p.isupper():
print "Your Password is weak as it only contains capital letters"
if p.islower():
print "Your Password is weak as it only contains lower case letters"
if p.isupper and p.islower:
print "Your Password is of medium strength, try adding some numbers"
try:
int(p)
print "Your Password is weak as it only contains numbers"
except (ValueError, TypeError):
pass
现在我需要的代码是,如果密码包含大小写字母和数字。
len(p) == 6 or 7 or 8 or 9 or 10 or 11 or 12:
应该改为6<=len(p)<=12
。 - Ashwini Chaudhary