我有这个密码检查器,每次你使用一个字母或一个小写字母给你一个点。这是代码。
def write_password():
points = 0
askpassword = input("enter in a password. only use the chasricters")
#char = "qwertyuiopasdfghjklzxcvbnmQERTYUIOPASDFGHJKLZXCVBNM"#
#askpassword = "qwe"#testing askpassword
chars = ["qwertyuiop","asdfghjkl",
"zxcvbnm","QWERTYUIOP","ASDFGHJKL","ZXCVBNM",]
#counts consectutive numbers
triples = []
for char in chars:
for i in range(len(char)-2):
triples.append(char[i:i+3])
input_string = askpassword.strip().lower()
for triple in triples:
if triple in input_string:
points += -5
# checks to see wather or not password has more than 8 charicters
for char in askpassword:
if char in askpassword:
if len (askpassword) >= 8:
points += 1
#checks to see if password has a capital letter
for chars in askpassword:
if (askpassword.isupper()):
points = points + 1
# checks to see if password has any lowercase letters
if (askpassword.islower()):
points = points + 1
else:
print("no points")
print("this password is worth",points,"points")
write_password()
每当我把一个小写字母或一个大写字母放入或展位时,我得到一个输出。我投入了多少输入,平方。 (例如输入= As。我的输出是4分)
这是你在找什么? Python有一个名为“string”的库,包含所有大写/小写字母。你可以定义自己的,但为什么不在它已经存在的时候使用它。
>>> import string
>>> string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> def checkpassword (passwd):
... points = 0
... if len (passwd) >= 8:
... points += 1
... for char in passwd:
... if char in string.ascii_letters:
... points += 1
...
... print ('Your password has a score of: ', points)
...
>>>
>>> checkpassword('Abdzf')
Your password has a score of: 0
>>> checkpassword('Abdzf2fdadf')
Your password has a score of: 11
>>> len ('Abdzf2fdadf')
11
如果您想要用户的输入,您可以这样做:
>>> def checkpassword ():
... points = 0
... passwd = input ('Enter a password: ')
... [...] # Rest of the code goes here
别忘了!即使我只有10个字符,不包括数字,但我的分数是11.额外的点是密码的长度大于或等于8,假设这是你想要的。