IndentationError:预期缩进块Analyze()Python 3

时间:2017-04-30 21:26:04

标签: python python-3.x function indentation

我正在使用python,当我调用我的函数时,它给了我这个:

  IndentationError: expected an indented block

错误,这非常令人沮丧,因为我检查了所有标签,看起来很好!有什么问题,任何人都可以帮助我,这似乎是一个简单而愚蠢的问题,但它不会消失!

Analyze()

在底部是抛出错误时突出显示的内容!

继承我的代码(我正在编写一个Jarvis AI):

#JARVIS mark 12  python 3.5.1 version
#JUST.A.RATHER.VERY.INTELEGENT.SYSTEM.
##import speech_recognition
##import datetime
##import os
##import random
##import datetime
##import webbrowser
##import time
##import calendar 
import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.tokenize import PunktSentenceTokenizer


#Brain functions, vocab!

what_i_should_call_someone = [""]

Good_Things = ["love","sweat","nice","happy","fun","awesome","great"]

Bad_Things = ["death","kill","hurt","harm","discomfort","rape","pain","sad","depression","depressed","angry","mad","broken","raging"]

Static_Greetings = ["hey","hello","hi","hey there","hi there","hello there"]

Sample_questions = ["what is the weather like","where are we today","why did you do that","where is the dog","when are we going to leave","why do you hate me","what is the Answer to question 8","what is a dinosour"]

possible_question_key_words = ["what's","what","where","when","why","isn't","this","that","what","is"]

Chance_that_question_was_asked_1 = 0

Chance_that_question_was_asked_2 = 0

certainty_question_was_asked = 0

Me_statment_keywords = ["you","your","yours"]

You_statment_keywords = ["i","i'm","me"]

global certainty_person_is_talking_to_me

the_last_thing_i_said = ("")

the_last_thing_person_said = ("")

what_person_said = ("")

what_person_said_means = [""]

what_im_about_to_say = [""]

why_im_about_to_say_it = [""]

who_im_talking_to = [""]

how_i_feel = [""]

why_do_i_feel_the_way_i_do = [""]

what_i_am_thinking = ("")

# ways to describe the nouns last said
it_pronouns = ["it","they","she","he"]

# last person place or thing described spoken or descussed!
last_nouns = [""]





while "Conversation":


    what_person_said = input()

    what_person_said1 = what_person_said.lower()

    what_person_said_wt = word_tokenize(what_person_said1)

        # try to define/name each word in the sentence! if the sentence is not as long as 9ish words it will except so it doest throw a index error!

             # word one in sentence 
    try: 
        word1 = what_person_said_wt[0]
    except IndexError:
        pass

             # word two in sentence
    try:
        word2 = what_person_said_wt[1]
    except IndexError:
        pass

             #sentence three in sentence
    try:
        word3 = what_person_said_wt[2]
    except IndexError:
        pass

    try:
        word4 = what_person_said_wt[3]

    except IndexError:
        pass

    try:
        word5 = what_person_said_wt[4]

    except IndexError:
        pass

    try:
        word6 = what_person_said_wt[5]

    except IndexError:
        pass


    try:
        word7 = what_person_said_wt[6]

    except IndexError:
        pass

    try:
        word8 = what_person_said_wt[7]

    except IndexError:
        pass


    try:
        word9 = what_person_said_wt[8]

    except IndexError:
        pass


    try:
        word10 = what_person_said_wt[9]

    except IndexError:
        pass


    try:
        word11 = what_person_said_wt[10]

    except IndexError:
        pass

    try:
        word12 = what_person_said_wt[11]

    except IndexError:
        pass


    try:
        word13 = what_person_said_wt[12]

    except IndexError:
        pass


    try:
        word14 = what_person_said_wt[13]

    except IndexError:
        pass


    try:
        word15 = what_person_said_wt[14]

    except IndexError:
        pass



    try:
        word16 = what_person_said_wt[15]

    except IndexError:
        pass


    try:
        word17 = what_person_said_wt[16]

    except IndexError:
        pass

    try:
        word18 = what_person_said_wt[17]

    except IndexError:
        pass

    try:
        word19 = what_person_said_wt[18]

    except IndexError:
        pass

    try:
        word20 = what_person_said_wt[19]

    except IndexError:
        pass



        def Analyze():

            def Analyze_for_question():
                        # problem i'm having is that the "for loop" devides by word and the keywords might be two words in a string seperated by a space, either
                        # i have to make all the question keywords one word or figure out how to fix this problem a different way!!
                for words in what_person_said_wt:
                    global Chance_that_question_was_asked_1
                    Chance_that_question_was_asked_1 = Chance_that_question_was_asked_1 + 1
                    if words in possible_question_key_words:
                        print (words)
                        print (Chance_that_question_was_asked_1)

                # This part will take the sentence and compare it with sample questions!

                Analyze_for_question()


            def Analyze_for_answer():
                # figure out if the last thing jarvis said was a question

                # if last_thing_i_said == Question:
                    # def Look_for_answer():








            Analyze()

2 个答案:

答案 0 :(得分:2)

python中的函数不能为空。注释掉的行不是有效内容。

这会给你一个IndentationError:

def test():
    # comment

要解决此问题,您需要添加pass。 (“什么都不做”)

def test():
    # comment
    pass

一个例外是你有一个docstring。

def test2():
    """This is a test"""

这里假设pass

答案 1 :(得分:0)

您的问题出在def Analyze_for_answer()(第232行)

此功能为空,删除注释或功能,或添加一行“pass”,问题将解决。

提示:功能名称的小写