如何解决如何将列表/字符串中的单词数添加到计数器?
我正在创建一个拼写检查程序,该程序将从字符串输入或文本文件中返回所有拼写错误的单词。我希望程序将拼写错误的单词的数量加起来,并将其打印为统计信息。
我似乎无法弄清楚如何计算列表中的单词数并将其添加到计数器中。
errorCount = 0
while True:
try:
selection = int(input("Would you like to enter a string (1),open a text file (2) or Quit (0) ?"))
if selection==1:
String = input("Please enter your string: ")
dictionaryList = readDictionaryFile(dictionaryFile)
stringList = readString(String)
errorList = findErrors(dictionaryList,stringList)
printErrors(errorList)
errorCount = errorCount + errorList.count()
解决方法
使用len(errorList)将返回列表中元素(错误)的数量
,def printErrors(errorList):
print ("The incorrectly spelled words are: ")
for words in errorList:
print(words)
多数民众赞成在打印声明,对不起
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。