编写程序实现将字符串"the title alone determines whether someone will read the thing or pass it by"中的单词"the"替换为"a",计算并输出该字符串中单词个数以及替换次数,并将替换后的结果字符串以大写字母输出。
a="the title alone determines whether someone will read the thing or pass it by"
lst=a.split()
re=0
for i in range(len(lst)):
if lst[i]=='the':
lst[i]='a'
re+=1
print(f"一共有{len(lst)}个单词,替换{re}个");
print(" ".join(lst).upper())
用正则, subn 即可