Statistical an English sentence contains two words have a few, and replaced with a two asterisks, can not count function
def count(s,x):
if (not isinstance(s,str)) or (not isinstance(x,str)):
return None
a = 0
i = 0
while i<=len(s)-1:
if s[i:i+len(x)]==x:
a = 1 +
i + = len (x)
else:
i+=1
Surely return
print(count("abcdbcd","bb"))
s = "I am a abandon,aaaa boy aabbaa aacc!"
s=list(s)
new_s=[]
for i in s: # filter punctuation, leaving only spaces and uppercase and lowercase letters
if i ==" " or ((i >="a" and i<="z") or \
(i >="A" and i<="Z")):
new_s.append(i)
else:
new_s.append(" ")
s="".join(new_s)
result_num=0
word_list = s.split () # list of words taken out
new_sentence = "result of" # stores the alternative
for word in word_list: # traversing the list of words
if count (word, "a") == 2: # 2 if there is a, then counted and replace the asterisk
result_num+=1
new_word = ""
for i in word: # find whether each letter is a
! If i = "a": # is not a reservation
new_word+=i
else: # is a is replaced with asterisks
new_word+="*"
new_sentence + = new_word + "" # stored in a new variable sentence
else:
new_sentence + = word + "" # stored in a new variable sentence
new_sentence = new_sentence [: - 1] # to remove the last blank
print ( "word comprising a total of:% s a"% result_num)
print(new_sentence)