编写一个程序,计算每个单词出现的次数

编写一个程序,从键盘上输入一段英文文本,然后计算每个单词出现的次数。要求统计方法使用函数实现。

str=("failure is probably the fortification in your pole it is like a peek your wallet as the thief "
"when you are thinking how to spend several hard-won lepta when you are wondering whether new money"
" it has laid background because of you then at the heart of the most lax alert and most low awareness"
" and left it godsend failed")
words=str.split() #拆分成列表
counts={}
print(f"单词总数是:{len(words)}")
for i in words:
counts[i]=counts.get(i,0)+1
i=0
for k,v in sorted(sorted(counts.items()),key=lambda x:x[1],reverse=True): #升序输出,前5个值
print(f"{k}:{v}")
i+=1
if i==5:
break