I'm using python and when i call my function it gives me this:
IndentationError: expected an indented block
Error, this is pretty frustrating because i have checked all the tabs and it looks fine! What is the problem, can anyone help me, it seems like a simple and dumb problem but it is not going away!
Analyze()
At the bottom is the thing highlighted when the error is thrown!
Heres my code (i'm coding a 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()
Functions cannot be empty in python. Lines commented out is not valid content.
This will give you an IndentationError:
def test():
# comment
To solve it you need to add a pass
. ("do nothing command")
def test():
# comment
pass
One exception is when you have a docstring.
def test2():
"""This is a test"""
here pass
is assumed.
def Analyze_for_answer()
(line 232) This function is empty, remove the comments or the function, or add one line with the word 'pass' and the problem will be solved.
Tip: Lower case for functions names
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.