这是我到目前为止所拥有的:
import string
所以我让用户写一个 5 字的句子,只要求 5 个字:
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
如果用户输入超过 5 个单词:
elif len(words)>5:
print 'Try again. Word exceeded 5 word limit'
少于5个字:
else:
print 'Try again. Too little words!'
它一直在说:
UnboundLocalError: local variable 'words' referenced before assignment