Python练习(二)

github上的第0009题,还有0011题。。。

直接上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
#coding:utf-8
#0009.py
import re,sys

def _find(fi):
try:
f = open(fi)
con = f.read()
except:
print '找不到此文件!'
print 'HTML文件中的url为:'
url = re.findall('[a-zA-Z]+://[^\s]+"',con) #正则匹配url
for i in url:
x = i.strip('"')
print x

if __name__ == '__main__':     
try:
fi = sys.argv[1]
_find(fi)
except:
try:
fi = raw_input('请输入HTML文件名:\n')
_find(fi)
except:
print '获取文件名失败!'

效果图:

效果图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
#coding:utf-8
#0011.py
import sys

f = open('filtered_words.txt')
con = f.read()
con1 = con.split()

def pei(tent):
if tent in con1:
print 'Freedom'
else:
print 'Human Rights'
def run():
while 1:
wri = raw_input()
if wri == '00':
break
pei(wri)

if __name__ == '__main__':
print '输入00来暂停程序~'
print '请输入词语:'
run()
print 'Over!'

效果图:
效果图