python小程序-0009

xiaoxiao2021-02-28  159

第9题:敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。

#!/usr/bin/env python3 # -*- coding : utf-8 -*- 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)
转载请注明原文地址: https://www.6miu.com/read-22577.html

最新回复(0)