Skip to content

Commit 3b085e5

Browse files
committed
0011 done
1 parent ee93fa7 commit 3b085e5

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

natezhang93/0011/censor.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
__author__ = 'natezhang93'
4+
5+
'''
6+
第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,
7+
当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
8+
'''
9+
10+
class Filter:
11+
def __init__(self):
12+
self.data = []
13+
try:
14+
with open("filtered_words.txt", 'r') as fin:
15+
self.data = (fin.read().splitlines())
16+
fin.close()
17+
except:
18+
raise IOError
19+
20+
def check(self, word):
21+
try:
22+
self.data.index(word)
23+
result = 'Freedom'
24+
except:
25+
result = 'Human Rights'
26+
return result
27+
28+
def main():
29+
try:
30+
fil = Filter()
31+
except:
32+
print "ERROR OPENING FILE"
33+
return
34+
35+
while True:
36+
word = raw_input("> ")
37+
word = fil.check(word)
38+
print word
39+
40+
if __name__ == "__main__":
41+
main()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
北京
2+
程序员
3+
公务员
4+
领导
5+
牛比
6+
牛逼
7+
你娘
8+
你妈
9+
love
10+
sex
11+
jiangge

0 commit comments

Comments
 (0)