1 Write the program to complete the following requirements:
- The number of individual characters in the statistics string
- For example, the result of the "Hello World" string statistic is: h:1 e:1 l:3 o:2 d:1 r:1 w:1
1 Print("-"*50)2 Print("*"*50)3CURRENTSTR = input ("Please input a sentence, the program would cal the word num:")4 5Currentstr=currentstr.replace (' ',"')## Delete the ' Space ' value6Newstr="' #a new string to store the result7 forIinchCurrentstr:8 if(Currentstr.count (i) <=1):#If there is only one word in currentstr9newstr=newstr+ITennewstr=newstr+':' OneNEWSTR=NEWSTR+STR (1) +' ' A Else:#The word has 2 or more numbers - if(Newstr.count (i) <1):#Have not register in the new string -Newstr= newstr+I thenewstr=newstr+':' -Newstr= Newstr+str (Currentstr.count (i)) +' ' - - Print("-"*50) + Print("The word number in this sentence is:%s"%newstr) - Print("-"*50) +
The results are as follows:
python2018-count of characters in a string