python 练习0011

版权声明:喜欢就点个赞吧,有啥疑问可以留言交流~ https://blog.csdn.net/m0_38015368/article/details/89328833

问题

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

北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge

代码

def get_words(file_name):
    try:
        with open(file_name, 'r') as f:
            return [word.strip() for word in f]
    except:
        print('Error')
        return ''

if __name__ == '__main__':
    file_name = 'filtered_words.txt'
    words = get_words(file_name)
    # print(words)
    while(True):
        line = input()
        if line == 'exit':
            break
        line = line.lower()
        if any(word in line for word in words):
            print('Freedom')
        else:
            print('Human Right')

猜你喜欢

转载自blog.csdn.net/m0_38015368/article/details/89328833
今日推荐