今天我試圖使用布爾表達式(True或False)來完成我的代碼;注意我把這個命令放在if processor['dictionary'] = True
。當代碼在那裏時它不能運行。但如果它不在那裏,它可以正常運行。我無法找到阻止我運行此代碼,錯誤作爲錯誤的原因:錯誤與真假
IndentationError: expected an indented block
希望你們能幫助我。
dictionary = {
"chicken":"chicken two leg animal",
"fish":"fish is animal that live under water",
"cow":"cow is big vegetarian animal",
"space monkey":"monkey live in space",
}
print("how can i help you?")
user_input = raw_input()
print
print("You asked: {}.".format(user_input))
processor = {
"dictionary":False,
"dictionary_lookup":[],
}
split = user_input.split(" ")
combos = [' '.join(split[x:y]) for x in range(len(split)) for y in range(len(split)+1) if ' '.join(split[x:y]) != ""]
for w in split:
w = w.lower()
if w in dictionary:
processor["dictionary"] = True
print w
print combos
# if processor ["dictionary"] = True
response = {}
for item in combos:
if dictionary.get(item):
response[item] = "what you were looking for is: {}.".format(dictionary[item])
if not response:
print("Response: I will get back to you!")
print
for ind, (k,v) in enumerate(response.iteritems()):
print("Response {}: {} ({})".format(ind+1, v, k))
print
請將您的代碼縮進4個空格作爲基線(您可以爲需要縮進的代碼縮進更多空格)。 –
「if」塊後面的代碼缺失或未正確縮進。 –
當我刪除#之前,如果。即使我嘗試正確縮進它,代碼仍然無法運行。我不知道我還想在哪裏修復。儘管它似乎是一個好的代碼。但是我想在#之後放行。 – saitama