所以我有这个代码,它接受密码输入并给它一个分数来显示密码的好坏。每当我尝试运行它时,它会给我以下错误消息,但我不知道它的含义。
TypeError Traceback(最近一次调用 最后)in() 22打印("此密码值得",积分,"积分") 23 ---> 24 write_password()
write_password()中的12 askpassword =" askpassword" .strip()。lower() 13三倍于三倍: ---> 14如果在askpassword中三倍: 15分+ = -5 16在askpassword中的char:
TypeError:' in'需要字符串作为左操作数,而不是列表
这是代码:
def write_password():
points = 0
#askpassword = input("enter in a password. only use the chasricters")
#char = "qwertyuiopasdfghjklzxcvbnmQERTYUIOPASDFGHJKLZXCVBNM"
askpassword = "asdf"
char = ["qwertyuiop","asdfghjkl", "zxcvbnm"]
triples = []
for chars in char:
for i in range(len(chars)-2):
triples.append(char[i:i+3])
askpassword = "askpassword".strip().lower()
for triple in triples:
if triple in askpassword:
points += -5
for char in askpassword:
if char in askpassword:
if len (askpassword) >= 8:
points = points + 1
else:
print("no points")
print("this password is worth",points,"points")
write_password()
请帮忙。提前谢谢。
答案 0 :(得分:0)
错误的具体含义非常简单。当您检查Python中是否存在某个字符串时,它需要某个字符串。在你的情况下,它是一个列表。您无法检查列表是否在字符串中。
在行for triple in triples
之前打印三元组将揭示你的神秘面纱,我怀疑上面的代码有问题。
[[' qwertyuiop',' asdfghjkl',' zxcvbnm'],[' asdfghjkl',' zxcvbnm&#39 ;],[' zxcvbnm'],[],[],[],[],[],[' qwertyuiop',' asdfghjkl',&# 39; zxcvbnm'],[' asdfghjkl',' zxcvbnm'],[' zxcvbnm'],[],[],[],[] ,[' qwertyuiop',' asdfghjkl',' zxcvbnm'],[' asdfghjkl',' zxcvbnm'], [' zxcvbnm'],[],[]]