В настоящее время я отвечаю на вопрос анализатора контента в 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 = 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 "", line 1
hello my name is amar. this is the text to be analyzed
^
SyntaxError: invalid syntax
Подробнее здесь: https://stackoverflow.com/questions/498 ... ntax-error
Столкнулся с неопознаваемой синтаксической ошибкой [дубликат] ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Можем ли мы исправить мою проблему с синтаксической ошибкой дубликатора в строке 10?
Anonymous » » в форуме Php - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Получение синтаксической ошибки при создании входного слоя для NN в тензорном потоке
Anonymous » » в форуме Python - 0 Ответы
- 31 Просмотры
-
Последнее сообщение Anonymous
-