В настоящее время я отвечаю на вопрос анализатора контента в 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
Программы на Python
-
Anonymous
1731306449
Anonymous
В настоящее время я отвечаю на вопрос анализатора контента в 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 "", line 1
hello my name is amar. this is the text to be analyzed
^
SyntaxError: invalid syntax
Подробнее здесь: [url]https://stackoverflow.com/questions/49806818/running-into-unidentifiable-syntax-error[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия