[Python Challenge] - Q6

Q6: now there are pairs

 

http://www.pythonchallenge.com/pc/def/channel.html

 

打开网页源文件可以看到“zip”的提示,下载得到channel.zip文件包。我解压文件后按照readme的提示写了一段代码用于找到其中正确的数字,得到结果“Collect the comments.”,原来答案在zip文件的注释里。得到结果:HOCKEY,打开hockey.html,得到“it's in the air. look at the letters. ”,正确答案为“oxygen”。

 

代码:

 

import zipfile import re def run (num): filename = num+".txt" comments.append(zip.getinfo(filename).comment) cont = zip.read(filename) m = p.findall(cont) if m: for mi in m: run (mi) else : return num = '90052' comments = [] zip = zipfile.ZipFile("channel.zip", "r") p = re.compile('[0-9]+') run (num) print "".join(comments)

找到提示信息“Collect the comments.”的代码:

import string import re def run (num): filename = num+".txt" file = open(filename) cont = file.readline() print cont file.close() m = p.findall(cont) if m: for mi in m: run (mi) else : return num = '90052' p = re.compile('[0-9]+') run (num)

你可能感兴趣的:(Python)