는 여기에 지금까지이 작업은 다음과 같습니다Python : 단어의 정확한 양을 묻는 함수를 만드는 방법은 무엇입니까?
그래서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
질문 할 때 문제가 무엇인지 말하십시오. – Kitsune
'string.split (sentence)'? Python2 이상으로 업그레이드해야합니다.'sentence.split()' –