在这个程序中,我正在计算字数,但由于某种原因它不起作用,我不知道为什么
#For this Programme I was trying to find out the word count and sentence count in a given text
sentence= ("I hope to fuck this works. It would mean great things to me.")
sent_count=0
word_count=sentence.split()
# here it counts the words in the senctence
numberofwords=len(word_count)
for ch in sentence:
if ch== ".":
sent_count +=1
# everything looks pefrect I dont know why it is not working
print("There are",numberofwords "words in this paragraph")
print("There are",sent_count"in this paragraph")
答案 0 :(得分:4)
您忘记了在,
中插入的变量末尾的逗号(print
):
print("There are", numberofwords, "words in this paragraph")