我用python编写了一个代码,并导入了所有需要的库。我解决了所有的错误,但我仍然得到一个语法错误
import enchant
from nltk.metrics import edit_distance
class SpellingReplacer(object):
def __init__(self, dict_name='en', max_dist=2):
self.spell_dict = enchant.Dict(dict_name)
self.max_dist = max_dist
def replace(self, word):
if self.spell_dict.check(word):
return word
suggestions = self.spell_dict.suggest(word)
if suggestions and edit_distance(word, suggestions[0]):
a=self.max_dist
return suggestions[0]
else:
return word
在最后的第二行中,它给出了语法错误,即在(else:)语句中使用了无效语法。我是根据我的知识做的。另外,w3resource中的语法 和我的一样。我不知道怎么解决。请帮帮我
您的第一个return语句应该缩进if下面。当前,else语句超出范围
相关问题 更多 >
编程相关推荐