1 print("-"*50)
2 print("*"*50)
3 currentstr = input("PLease input a sentence, the program will cal the word num:")
4
5 currentstr=currentstr.replace(' ','')## Delete the 'Space' value
6 newstr='' #a new string to store the result
7 for i in currentstr:
8 if(currentstr.count(i)<=1):# if there is only one word in currentstr
9 newstr=newstr+i
10 newstr=newstr+':'
11 newstr=newstr+str(1)+' '
12 else:#the word has 2 or more numbers
13 if(newstr.count(i)<1): # has not register in the new string
14 newstr= newstr+i
15 newstr=newstr+':'
16 newstr= newstr+str(currentstr.count(i))+' '
17
18 print("-"*50)
19 print("The word number in this sentence is : %s"%newstr)
20 print("-"*50)
21