python拼写错误20几分钟怎么办_Python拼写检查及建议

我需要一个程序来检查它的输入是否正确。不过,我想回一两个建议,以及这个人的意思。有什么建议吗?我发现了一些模块可以做到这一点,但不是针对一个特定的字典从一个文件。感谢任何帮助!!在

我现在的情况是:def getDictionary():

theDictionary = open("theDictionary.txt", "r")

dictionaryList = []

for eachLine in theDictionary:

splitLines = eachLine.split()

dictionaryList.append(splitLines[0])

theDictionary.close()

return dictionaryList

def spellChecker(theFile, theDictionary):

lowerItems = theFile.lower()

wordList = lowerItems.split()

wrongList = []

for item in wordList:

if item not in theDictionary:

result = False

wrongList.append(item)

else:

result = True

wrongItem = ""

return (result, wrongList)

def main():

theDictionary = getDictionary()

theText = getFile()

theInput = input("Input some words here:")

result, wrongList=spellChecker(theInput,theDictionary)

if result:

print("There are no spelling errors in the sentence! Hooray!")

else:

if len(wrongList) == 1:

print('There is a spelling error in the sentence! The word that is wrong is "' + str(wrongList) + '".')

elif len(wrongList) > 1:

print('There are some spelling errors in the sentence! The words that are wrong are"' + str(wrongList) + '".')

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值