# 第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
# 第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,
# 例如当用户输入「北京是个好城市」,则变成「**是个好城市」。
import re
def read_txt(file):
with open(file) as f:
data = f.read()
# print(type(data),data)
list_data = data.split('\n')
# print(list_data)
return list_data
def get_input():
input_word = input('please input:')
for word in read_txt('0011.txt'):
if word in input_word:
print('Freedom')
p = re.sub(word,'*',input_word)
return p
return 'Human Rights'
if __name__ == "__main__":
print(get_input())
0011.txt
北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge