我目前正在python中进行内容分析器问题,但是当我运行程序时没有正确的输出。我只是寻求帮助和额外的眼睛来看我的代码并引导我朝着正确的方向前进。
这是我的代码:
def clean_text(filetext):
# cleaning up the file by turning it into a single string, removing punctuation, and making it lower case
text = filetext.lower().split(" ")
sentences = filetext.split(".")
u_words = {}
wordcount = 0
u_wordcount = 0
sentencecount = 0
sentencelength = 0
# update the counter to keep track of unique words
for i in text:
wordcount = wordcount + 1
if i in u_words:
u_words = u_words + 1
else:
u_words[i] = 1
u_wordcount = u_wordcount + 1
# update counter to keep track of number of sentences
for x in sentences:
sentencecount = sentencecount + 1
sentencelength = sentencelength + len(x)
averagelength = 0
if sentencecount > 0:
averagelength = sentencelength / sentencecount
# Print the results in the same order given to us
print ("Total word count:", wordcount)
print ("Unique Words:", u_wordcount)
print ("Sentences:", sentencecount)
print("Average Sentence Length:", averagelength)
filetext = input("Enter text to be analyzed: ")
clean_text(filetext)
这是错误:
filetext = input("Enter text to be analyzed: ")
File "<string>", line 1
hello my name is amar. this is the text to be analyzed
^
SyntaxError: invalid syntax