閱讀資料 第 0011 題: 敏感詞文本檔案 filtered_words.txt,裡面的内容為以下内容,當使用者輸入敏感詞語時,則列印出 Freedom,否則列印出 Human Rights。
- 北京
- 程式員
- 公務員
- 上司
- 牛比
- 牛逼
- 你娘
- 你媽
- love
- sex
- jiangge
def get_filters(path):
if path is None:
return
filters = ["北京", "程式員", "公務員", "上司", "牛比", "牛逼", "你娘", "你媽", "love", "sex", "jiangge"]
with open(path,encoding="utf-8") as f:
line = f.read()
# for line in (open(path, "w", encoding="utf-8").readlines()):
if "\n" in line:
filters.append(line[:-1])
else:
filters.append(line)
f.close()
return filters
def main():
filters = get_filters("text.txt")
while True:
temp = input("plz input:")
if temp == "0":
print("Exit")
break
else:
if temp in filters:
print("Freedom")
else:
print("Human Rights")
if __name__ == "__main__":
main()