Question

Here's what I have so far:

import string

So I have the user write a 5 worded sentence asking for only 5 words:

def main(sentence = raw_input("Enter a 5 worded sentence: ")):
    if len(words)<5:
        words = string.split(sentence)
        wordCount = len(words)
        print "The total word count is:", wordCount

If the user inputs more than 5 words:

    elif len(words)>5:
        print 'Try again. Word exceeded 5 word limit'

Less than 5 words:

    else:
        print 'Try again. Too little words!'

It keeps stating that:

UnboundLocalError: local variable 'words' referenced before assignment

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top