

Pythonを勉強している初心者です。  
以下のコードで、text
file内の英文を読み取って、statement（命題）として成立する文かそうじゃないかを分別するプログラムを練習で作っているのですが、分別する際のキーワードを並べた2行目のlistが21行目のelif構文内でうまく機能していないようです。  
どうして動かないのか、どうすれば正しく動作するか、もしよろしければ教えて下さい。

使ったtext file の内容

[code]

    Strawberries are fruit.
    Do you like grape jelly?
    The Church is true.
    She sings well.
    2 + 2 = 5
    how are you doing
    Go.
    School is located in Japan
    
[/code]

コード内容

[code]

    from sys import argv
    
    
    qWord = ["what","where","how","why","who","when","he","she","it","they"]
    
    if len (argv) == 1:
        print ("Type argument/filename.") 
    else:
        filename = argv[1]
        try:
            with open(filename) as file:
                contents = file.read()
        except IOError:
            print("No File Found")
        else:
    
            file = open(filename)
       #process to open the file
    
    
            for line in file: 
                line = line.rstrip()
    
                if line[-1] == "?":
                    print(line+" NOT A STATEMENT")
    
                elif " " not in line: 
                    print(line+" NOT A STATEMENT")
    
                elif line in qWord:
                    print(line+" NOT A STATEMENT")
                else:
                    print(line+" STATEMENT")
    
[/code]

コマンドライン内で本来の趣旨に則って動作した場合の反応

[code]

    Strawberries are fruit. STATEMENT
    Do you like grape jelly? NOT A STATEMENT
    The Church is true. STATEMENT
    She sings well. NOT A STATEMENT
    2 + 2 = 5 STATEMENT
    how are you doing NOT A STATEMENT
    Go. NOT A STATEMENT
    School is located in Japan STATEMENT
    
[/code]

実際の反応

[code]

    Strawberries are fruit. STATEMENT
    Do you like grape jelly? NOT A STATEMENT
    The Church is true. STATEMENT
    She sings well. STATEMENT
    2 + 2 = 5 STATEMENT
    how are you doing STATEMENT
    Go. NOT A STATEMENT
    School is located in Japan STATEMENT
    
[/code]


CC BY-SA 4.0
2020-01-28T06:24:30.733
62605
2020-01-29T07:32:52.370
2020-01-28T06:31:11.677
37615
37615
question
python
Python でtext file 内の英文を読み取ってキーワードにのっとって文を種類分けするとき、コード内のlistを読み取りません


頂いたアドバイスを元に無事動作したコードを下記に載せます。  
助けて下さりありがとうございました！

[code]

    from sys import argv
    
    questionSig = '?'
    space = ' '
    qWord = ["what","where","how","why","who","when","he","she","it","they"]
    
    if len (argv) == 1:
        print ("Type argument/filename.") 
    else:
        filename = argv[1]
        try:
            with open(filename) as file:
                contents = file.read()
        except IOError:
            print("No File Found")
        else:
    
            file = open(filename)
       #process to open the file
    
    
    
            for line in file: 
                line = line.rstrip()
    
    
                if any(word in line for word in qWord):
                    print(line+" NOT A STATEMENT")
    
    
                elif " " not in line: 
                    print(line+" NOT A STATEMENT")
    
                elif line[-1] == "?":
                    print(line+" NOT A STATEMENT")
                else:
                    print(line+" STATEMENT")
    
    
[/code]


CC BY-SA 4.0
2020-01-29T07:32:52.370
62635
2020-01-29T07:32:52.370
37615
62605
answer