the python challenge

来源:互联网 发布:晴天软件 编辑:程序博客网 时间:2024/06/05 10:00

1:   第一题:图片左左上角为0 html 地址为0.html  图片内容为 2的38次幂  利用python 2 ** 38 得出 274877906944 替换地址栏中的0得出下一页地址:http://www.pythonchallenge.com/pc/def/274877906944 .html


2:第二题为加密解密问题 :

 enc_str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."

out_str = ""


for letter in enc_str:
    letter_ = ord(letter) + 2
    if ord(letter) >= 97 and ord(letter) <= 122:
        if letter_ >= 122:
            letter_ = letter_ - 26
        print chr(letter_)
        out_str += chr(letter_)
    else:
        out_str += letter


print out_str

为:i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.

将地址中map 按照图片的加密算法 得出下一页地址:http://www.pythonchallenge.com/pc/def/ocr.html

3,查看页面源代码。可以看到一大最的特殊字符。根据提示是找出所有字母中频率最少的的字母,我用了一个比较笨的办法,得出equality:



with open("cha3.txt", "r") as f:
    file_content = f.read()


rate_dict = {}


for letter in file_content:
    if letter in rate_dict:
        rate_dict[letter] = rate_dict[letter] +1
    else:
        rate_dict[letter] = 1

4: 第四题是正在表达式问题 ,找出一个小写字母 并且两边各有三个大写字母, 得出linkedlist。

import re


file_content = ""


with open("cha4.txt", "r") as f:
    file_content = f.read()


test_re = re.compile(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')


result = test_re.findall(file_content)


if result:
    print "".join(result)


5:



import urllib2




need_devide =True
def get_nothing():
    nothing = 69288
    for x in xrange(400):
        url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s" % nothing
        content = urllib2.urlopen(url).read()
        nothing = content.split(" ")[-1]
        print x, nothing, content
        if not nothing.isdigit():
            if need_devide:
                nothing = int(nothing) / 2
                need_devide = False
            else:
                break




if __name__ == "__main__":
    get_nothing()





0 0
原创粉丝点击