码迷,mamicode.com
首页 > 编程语言 > 详细

python每日一练:0011题

时间:2019-07-14 20:13:02      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:lte   txt   else   文件   with open   文本   情况   ==   pytho   

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

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

示例代码:
inputs = input(请输入内容:)
with open(filtered_words.txt,r,encoding=utf-8) as f:
    while True:
        word = f.readline().strip()
        if word == ‘‘:  # 文档结束标志
            print(" Human Rights")
            break
        else:
            if inputs.find(word) >= 0:  #inputs.find() 匹配到的情况下返回索引值(大于等于0),找不到返回-1
                print(" Freedom!")
                break

 

python每日一练:0011题

标签:lte   txt   else   文件   with open   文本   情况   ==   pytho   

原文地址:https://www.cnblogs.com/xuxiaowen1990/p/11185244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!