NLP User specific Text Corpora python 虽然程序提供正确的输出,但在 hackerrank 中出现运行时错误

NLP User specific Text Corpora python getting Runtime error in hackerrank though program giving correct output

    import nltk
    
    from nltk.corpus import PlaintextCorpusReader
    
    import nltk.data
    
    import os
    
    def createUserTextCorpora(filecontent1, filecontent2): 'user text corpora'
    
        with open(os.path.join('nltk_data/','content1.txt'),"w") as file1:
            file1.write(filecontent1) 'write the filecontent1 to content1.txt'
            file1.close()
        with open(os.path.join('nltk_data/','content2.txt'),"w") as file2:
            file2.write(filecontent2)  'write the filecontent2 to content2.txt'
            file2.close()
    
        text_corpus = PlaintextCorpusReader('nltk_data/','.*')  'converting the txt files to text corpus'
        no_of_words_corpus1 = len(text_corpus.words('content1.txt'))
        no_of_words_corpus2 = len(text_corpus.words('content2.txt'))
        no_of_unique_words_corpus1 = len(set(text_corpus.words('content1.txt')))
        no_of_unique_words_corpus2 = len(set(text_corpus.words('content2.txt')))
    
        print(no_of_words_corpus1)
        print(no_of_unique_words_corpus1)
        print(no_of_words_corpus2)
        print(no_of_unique_words_corpus2)
    
    if __name__ == '__main__':
        
        filecontent1 = input()
        filecontent2 = input()
        createUserTextCorpora(filecontent1, filecontent2)

'当我们运行这个程序时,它给出了如上的输出,但在hackerrank控制台中抛出运行时间错误作为编译器消息。我的输出和预期输出匹配所有测试用例,但最终以所有测试用例均未通过而结束。 '

' filecontent1 = 琥珀色的水滴挂在树枝上,饱满并准备掉落。它等待着。虽然许多其他液滴满足于尽可能大地形成并释放,但这个液滴有其他计划。它想成为历史的一部分。它希望在所有其他液滴都融入历史之后很久才被记住。所以它等待完美的标本飞过并捕获它希望在未来数百年内最终被发现。'

'filecontent2 = 从今天开始!”便条上写的就是这些。没有任何迹象表明它是从哪里来的,也没有说明它可能是谁写的。它是写给其他人的吗?梅根环顾了整个房间,但没有人知道目光接触回来。有那么一瞬间,她认为这可能是一个让她追随梦想的信息,但最终她决定忽略它更容易,因为她把它揉成一团扔掉了。'

' 输出:

94

61

86

66 

' Screenshot 1 Screenshot 2

删除 print 语句并添加 return 语句:

return text_corpus,no_of_words_corpus1,no_of_unique_words_corpus1,no_of_words_corpus2,no_of_unique_words_corpus2