0

I am currently doing a content analyzer question in python, however no proper output is coming when I run the program. I was just looking for help and an extra set of eyes to look at my code and lead me in the right direction.

Here is my code:

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)

and here is the error:

        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
  • 3
    You either want to use python version 3, or use the function raw_input. I'd suggest downloading the newest version of Python. – Arya Apr 12 '18 at 22:36
  • See https://stackoverflow.com/questions/2589309/command-line-input-causes-syntaxerror – Arya Apr 12 '18 at 22:36
  • In python 2 `input()` tries to compile what is typed in as a python program. Python 3 is the "new" python - it was first released nearly a decade ago so scratch that "new". Upgrade if at all possible. – tdelaney Apr 12 '18 at 22:38

0 Answers0