Python练手项目0011

本项目采用的是https://github.com/Yixiaohan/show-me-the-code中所提供的练习项目,所有代码均为原创,转载请注明,谢谢

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

# -*- coding: utf-8 -*-

"""
Created on Thu Jan 12 13:55:35 2017


@author: sky
"""
def trans_to_words():
    type_in = raw_input(">")
    judge_flag = False
    fout = open('reslut.txt','w')
    with open('1.txt') as f:
        text = f.read().decode('gbk').encode('gbk')


    for i in text.split("\n"):
        if i in type_in:
            judge_flag = True


    if judge_flag:
        print "Freedom"
        fout.write('Freedom')
    else:
        print "Human Rights"
        fout.write('Human Rights')


    fout.close


if __name__ == "__main__":

    trans_to_words()


注意:

里面涉及到汉字转码,可以参考http://www.111cn.net/phper/python/38513.htm

详细代码和结果,可以参考https://github.com/g8015108/exercise-for-python

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值