mardi 26 octobre 2021

[Python]I have an indent problem in nested if statements at the below codes

enter image description here As in the image, I would like to categorize questions into 5 levels. I am writing an if statement and have an indent problem in nested if statements at the below codes. I have kept seeing IndentationError: unexpected indent Could you help me to check the indentation?


def determine_question():
    stringline=line.replace("\r","")
    stringline=stringline.replace("\n","")

#Determining LEVEL 2 QUESTIONS
    if contains_word(stringline.lower(), 'what'): # indent 4
        if contains_word(stringline.lower(), 'do') or contains_word(stringline.lower(), 'does') or contains_word(stringline.lower(), 'did'): # indent 8
            
            #Instead to determining LEVEL 2 QUESTIONS, Jumping to LEVEL 3 based on vocabulary
                if contains_word(stringline.lower(), 'explain') or contains_word(stringline.lower(), 'example') or contains_word(stringline.lower(), 'result') or contains_word(stringline.lower(), 'show') or contains_word(stringline.lower(), 'differ'): # indent 16
                    resultfile.write(stringline + ' - Level 3 - based on directive verb' + "\n")
                    return None
                if contains_word(stringline.lower(), 'could') or contains_word(stringline.lower(), 'can') or contains_word(stringline.lower(), 'would') or contains_word(stringline.lower(), 'will') or contains_word(stringline.lower(), 'might') or contains_word(stringline.lower(), 'should') or contains_word(stringline.lower(), 'shall'):      
                    resultfile.write(stringline + ' - Level 3 - based on directive verb' + "\n")  
                    return None
            
                #Instead to determining LEVEL 2 QUESTIONS,Jumping to LEVEL 4 based on vocabulary
                
                if contains_word(stringline.lower(), 'mean') or contains_word(stringline.lower(), 'infer') or contains_word(stringline.lower(), 'interpret'):
                    resultfile.write(stringline + ' - Level 4 - based on directive verb' + "\n")  
                    return None
                
                if contains_word(stringline.lower(), 'summarize') or contains_word(stringline.lower(), 'recommend') or contains_word(stringline.lower(), 'evaluate') or contains_word(stringline.lower(), 'consider'):
                    resultfile.write(stringline + ' - Level 4 - based on directive verb' + "\n")  
                    return None
                                
                else:
                    resultfile.write(stringline + ' - Level 2' + "\n")
                    return None
                
                
    if contains_word(stringline.lower(), 'which'):
        if contains_word(stringline.lower(), 'do') or contains_word(stringline.lower(), 'does') or contains_word(stringline.lower(), 'did') or contains_word(stringline.lower(), 'is') or contains_word(stringline.lower(), 'was') or contains_word(stringline.lower(), 'are') or contains_word(stringline.lower(), 'can') or contains_word(stringline.lower(), 'could') or contains_word(stringline.lower(), 'would') or contains_word(stringline.lower(), 'will') or contains_word(stringline.lower(), 'might') or contains_word(stringline.lower(), 'should') or contains_word(stringline.lower(), 'shall') or contains_word(stringline.lower(), 'of'):
                resultfile.write(stringline + ' - Level 2' + "\n")  
                return None

    if contains_word(stringline.lower(), 'who'):
        if contains_word(stringline.lower(), 'can') or contains_word(stringline.lower(), 'could') or contains_word(stringline.lower(), 'would') or contains_word(stringline.lower(), 'will') or contains_word(stringline.lower(), 'might') or contains_word(stringline.lower(), 'should') or contains_word(stringline.lower(), 'shall'):
                resultfile.write(stringline + ' - Level 2' + "\n")  
                return None
                
    if contains_word(stringline.lower(), 'when'):
        if contains_word(stringline.lower(), 'do') or contains_word(stringline.lower(), 'does')  or contains_word(stringline.lower(), 'are') or contains_word(stringline.lower(), 'can') or contains_word(stringline.lower(), 'could') or contains_word(stringline.lower(), 'would') or contains_word(stringline.lower(), 'will') or contains_word(stringline.lower(), 'might') or contains_word(stringline.lower(), 'should') or contains_word(stringline.lower(), 'shall'):
                resultfile.write(stringline + ' - Level 2' + "\n")  
                return None
                                 
    if contains_word(stringline.lower(), 'where'):
        if contains_word(stringline.lower(), 'do') or contains_word(stringline.lower(), 'can') or contains_word(stringline.lower(), 'could') or contains_word(stringline.lower(), 'would') or contains_word(stringline.lower(), 'will') or contains_word(stringline.lower(), 'might') or contains_word(stringline.lower(), 'may') or contains_word(stringline.lower(), 'should') or contains_word(stringline.lower(), 'shall'):
                resultfile.write(stringline + ' - Level 2' + "\n")  
                return None

    if contains_word(stringline.lower(), 'how many') or contains_word(stringline.lower(), 'how much'):
            if contains_word(stringline.lower(), 'do') or contains_word(stringline.lower(), 'does') or contains_word(stringline.lower(), 'did') or contains_word(stringline.lower(), 'is') or contains_word(stringline.lower(), 'was') or contains_word(stringline.lower(), 'are') or contains_word(stringline.lower(), 'were') or contains_word(stringline.lower(), 'can') or contains_word(stringline.lower(), 'could') or contains_word(stringline.lower(), 'would') or contains_word(stringline.lower(), 'will') or contains_word(stringline.lower(), 'might'):
                resultfile.write(stringline + ' - Level 2' + "\n")            
                return None

Aucun commentaire:

Enregistrer un commentaire