概述
我看过与我的问题Password check- Python 3类似的另一篇文章,只是我的问题涉及检查密码是否同时包含大写和小写问题。我的代码如下,但当执行时,它无法识别密码中的小写和大写字母,它只能识别一种类型。我怎样才能让它识别这两种类型?另外,如果所有这些值都发生了,不必为每个单独的步骤生成函数,是否有一种更简单的方法来检查代码?def Get_Password():
return input("Enter your desired password: ")
def Count_Digits(password):
return sum(character.isdigit() for character in password)
def Valid_password_length(password):
if len(password) >= 10:
return ('step1' == True)
else:
return ('step1' == False, print("Invalid password: too short"))
def Valid_password_characters(password):
if password.isalnum():
return ('step2' == True)
else:
return ('step2' == False, print("Invalid password: illegal character detected"))
def Valid_password_numdigit(password):
if Count_Digits(password) >= 2:
return ('step3' == True)
else:
return ('step3' == False, print("Invalid password: Must have at least 2 digits"))
def Valid_password_lowercase(password):
for i in (password):
if i.islower() == True:
return ('step4' == True)
else:
return ('step4' == False, print("Invalid password: No lowercase characters detected"))
def Valid_password_uppercase(password):
for i in (password):
if i.isupper() == True:
return ('step5' == True)
else:
return ('step5' == False, print("Invalid password: No uppercase characters detected"))
def password_checker():
password = Get_Password()
Valid_password_length(password)
Valid_password_characters(password)
Valid_password_numdigit(password)
Valid_password_lowercase(password)
Valid_password_uppercase(password)
if 'step1' and 'step2' and 'step3' and 'step4' and 'step5' == True:
print("Congratulations! This password is valid")
password_checker()
最后
以上就是传统金针菇为你收集整理的python检查密码字符串是否规范_在python中,如何检查字符串是否同时包含大小写字母...的全部内容,希望文章能够帮你解决python检查密码字符串是否规范_在python中,如何检查字符串是否同时包含大小写字母...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复