Hello guys!!
I really need your help, I'm starting to use python and I have to write a program that counts the letters of a sentence entered by the user. This is what I have so far, but I don't know why it is not working.. Please help, thank you

def main():
    phrase = input("Enter a sentence:")
    words = phrase.split
    wordCount = len(words)
    print("The total word count is:")
main()

Edited 1 Month Ago by Reverend Jim: Corrected code formatting

Value of words will be the method for splitting strings. Maybe that is not what you want.

You have some mistake,and use code tag.
See if this help.

def main():
    phrase = input("Enter a sentence:")
    words = phrase.split() #Forget ()
    wordCount = len(words)
    print("The total word count is: %s" % wordCount) #You have to include wordCount in print
main()

Another flavour....;)

def main():
    print len([x for x in raw_input("enter a phrase:" ).split()])
main()

Edited 5 Years Ago by richieking: n/a

def main():
    print len([x for x in raw_input("enter a phrase:" ).split()])
main()

Just FYI: I receive a SyntaxError: invalid syntax when I tested this code in Python 3.1.3.

The function named "raw_input" in Python 2.x is named "input" in Python 3.x . Since you did not specify what version of Python you use (until your last post), people were naturally confused. More so since many many more Python 2.x users than 3.x.

Hope I didn't confuse you Fo.katia. I just wanted to point out that there are some difference between Python versions 2 & 3 that we new guys could get lost on.

    # - *- coding: utf- 8 - *-
    def words(string):
        wordstr = string.split() 
        wordict = {} # dictionary to holds the word against count
        for word in wordstr:
            if word in wordict:
                wordict[word] += 1
            else:
                wordict[word] = 1
        return wordict

Edited 1 Month Ago by Peter_38