第9题:敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
def filters(filterpath):
filterword = []
with open(filterpath)
as f:
for line
in f.readlines():
line = line.strip(
'\n')
filterword.append(line)
print(filterword)
while 1:
inputstr = input(
"请输入任何你想输入的文字:")
if inputstr
in filterword:
print(
"Freeedom")
else:
print(
"Human Rights")
if __name__ ==
"__main__":
filterpath = input(
"请输入过滤文本路径:")
if filterpath
is not None:
filters(filterpath)