Quantcast
Viewing all articles
Browse latest Browse all 7

python challenge level 6

继续写python challege,现在是level 6

题目链接

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

思路

单看页面,也是看不出什么结果,那只好继续查看页面源代码了

只有这么一个有用的信息

<!-- <-- zip -->

把channel.html换成zip.html又或者下载channel.zip文件?

后面发现是下载channel.zip,打开channel.zip文件

里面有个readme.txt,其内容如下:

welcome to my zipped list.

hint1: start from 90052
hint2: answer is inside the zip

从90052.txt开始,然后发现90052.txt也是一串数字,这个和前面的nothing题目类似,我们不妨先把txt里面的数字依次读取出来

输出结果

Collect the comments.

这个我就就不太懂了,到网上找了一下,据说是zip文件中有一个属性是comment属性,根据这个特性,写出如下代码:

#!/usr/bin/env python3

import zipfile

def get_one_file(filename):
    try:
        with open(filename) as f:
            return f.readline();
    except:
        print("file not exist")
        return -1;

dir = "channel/"
name = "90052"

zip_file = zipfile.ZipFile("channel.zip")
comments = []


while(1):
    filename = dir + name + ".txt"
    zip_filename = name + ".txt"
    line = get_one_file(filename)
    if(line == -1):
        break;

    comments.append(zip_file.getinfo(zip_filename).comment.decode('utf-8'))
    print (line)
    lines = line.split(' ')
    length = len(lines)
    name = lines[length - 1]

print (comments)
print ("".join(comments))

输出结果:

****************************************************************
****************************************************************
**                                                            **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE NN      NN  **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE  NN    NN   **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE       NN  NN    **
**   OOOOOOOO XX    XX YY        GGG       EEEEE     NNNN     **
**   OOOOOOOO XX    XX YY        GGG       EEEEE      NN      **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE         NN      **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE     NN      **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE     NN      **
**                                                            **
****************************************************************
 **************************************************************

输入hockey.html

页面显示

it's in the air. look at the letters.

发现hockey中的每个大字母都是由一些小字母组成,提取里面的小字母oxygen

输入oxygen.html

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

进入level 7


Viewing all articles
Browse latest Browse all 7

Trending Articles