2017-12-23 1 views
0

で助けてください。このコードでは、パスワード入力を受け取り、パスワードの良さと悪さを示すスコアを付けています。私はそれを実行しようとするたびに、それは私に次のエラーメッセージを与え、私はそれが何を意味するのか分からない。タイプエラー


TypeError Traceback (most recent call last) in() 22 print("this password is worth",points,"points") 23 ---> 24 write_password()

in write_password() 12 askpassword = "askpassword".strip().lower() 13 for triple in triples: ---> 14 if triple in askpassword: 15 points += -5 16 for char in askpassword:

TypeError: 'in ' requires string as left operand, not list

そして、これはコードです:

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

エラーの具体的な意味は非常に簡単です。 Pythonで何かが文字列内にあるかどうかを調べるときには、何かが文字列であることが必要です。あなたの場合、それはリストです。リストが文字列内にあるかどうかはチェックできません。

行の前にトリプルを印刷するfor triple in triplesはあなたの謎に光を当て、上のコードで何か間違っていると思われます。

[['qwertyuiop', 'asdfghjkl', 'zxcvbnm'], ['asdfghjkl', 'zxcvbnm'], ['zxcvbnm'], [], [], [], [], [], ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'], ['asdfghjkl', 'zxcvbnm'], ['zxcvbnm'], [], [], [], [], ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'], ['asdfghjkl', 'zxcvbnm'], ['zxcvbnm'], [], []]