python 输入数字变成密码_如何在python中检查数字的“密码”
我建議使用sets和stdlib中的string包作為可接受字符的列表。在
我還建議進(jìn)行一點(diǎn)重構(gòu),以刪除大量帶有if / else分支的嵌套。在import string
upper = set(list(string.uppercase))
lower = set(list(string.lowercase))
numbers = set(list(string.digits))
while True:
npw = input("Please enter new password: ")
npwc = input("Please confirm new password: ")
if npwc != npw:
print("Passwords don't match")
continue
if len(npcw) < 8:
print("Your password must contain at least 8 characters.")
continue
chars = set(list(npwc))
if not upper.intersection(chars):
print("Your password must contain at least 1 upper case character.")
continue
if not lower.intersection(chars):
print("Your password must contain at least 1 lower case character.")
continue
if not numbers.intersection(chars):
print("Your password must contain a number")
continue
npw = npwc
print("Your password has been changed")
break
總結(jié)
以上是生活随笔為你收集整理的python 输入数字变成密码_如何在python中检查数字的“密码”的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 宋城门票多少钱啊?
- 下一篇: android 录音原始文件_音频采集: