繁体   English   中英

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

[英]IndentationError: expected an indented block Analyze() Python 3

我正在使用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()

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

这会给你一个IndentationError:

def test():
    # comment

要解决它,您需要添加一个pass (“不执行任何命令”)

def test():
    # comment
    pass

一个例外是您拥有文档字符串。

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

这里假设pass

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

该函数为空,删除注释或函数,或在一行中添加“ pass”一词,即可解决问题。

提示:函数名称的小写字母

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM