python练题--游戏式闯关挑战

来源:互联网 发布:剖腹产算日子软件下载 编辑:程序博客网 时间:2024/05/17 01:22

主页:http://www.pythonchallenge.com/

第一题:http://www.pythonchallenge.com/pc/def/0.html

>print pow(2,38)>274877906944

第二题:http://www.pythonchallenge.com/pc/def/map.html
def tranChar(s):    if s==" " or s=="\'" or s==".":        t = s    elif s=="y":        t = "a"    elif s=='z':        t = 'b'    else:        t = chr(ord(s)+2)    return tstr = "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."s = ""for i in str.strip(" "):    s = s+tranChar(i)print s

经典解法:

print "".join(map(lambda x: x.isalpha() and chr((ord(x)+2-ord("a"))%26 + ord("a")) or x, input))


第三题:http://www.pythonchallenge.com/pc/def/ocr.html

tips:在该网页的源码找题目!

find rare characters in the mess below:

print "".join(map(lambda x: x.isalpha() and x or "",mess))

第四题:http://www.pythonchallenge.com/pc/def/equality.html
tips:在该网页的源码找题目!

reg = r'[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]'re_mess_pattern = re.compile(reg)r = re_mess_pattern.findall(mess)print "".join(r)

第五题:http://www.pythonchallenge.com/pc/def/linkedlist.php

要解决的问题是:你点击哈图片,就知道了!
然后链接就变成了:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

import urllib,re,timeuri = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s"reg = r"and the next nothing is (\d+)"num = "8022"while True:    try:        source = urllib.urlopen(uri % num).read()        # print source        num = re.search(reg,source).group(1)        print num    except:        breakprint "Result is:",num

中间还要折腾两次~


第六题:http://www.pythonchallenge.com/pc/def/peak.html
还是看源码找问题:
peak hell sounds familiar ? 使用pickle
发现链接:http://www.pythonchallenge.com/pc/def/banner.p

import urllib,pickleuri = 'http://www.pythonchallenge.com/pc/def/banner.p'data = urllib.urlopen(uri)tdata = pickle.load(data)for i in tdata:    print "".join([j[1]*j[0] for j in i])  #j[1]表示生成#的个数,j[0]表示空格或者#
              #####                                                                      #####                ####                                                                       ####                ####                                                                       ####                ####                                                                       ####                ####                                                                       ####                ####                                                                       ####                ####                                                                       ####                ####                                                                       ####       ###      ####   ###         ###       #####   ###    #####   ###          ###       ####    ###   ##    #### #######     ##  ###      #### #######   #### #######     ###  ###     ####   ###     ###  #####    ####   ###   ####    #####    ####  #####    ####   ###     ###   ####  ###           ####     ####   ###    ###    ####     ####  ####     ####  ###      ####  ####  ###           ####     ####          ###    ####     ####  ####     ####  ###       ###  #### ####           ####     ####     ##   ###    ####     ####  ####     #### ####       ###  #### ####           ####     ####   ##########    ####     ####  ####     #### ##############  #### ####           ####     ####  ###    ####    ####     ####  ####     #### ####            #### ####           ####     #### ####     ###    ####     ####  ####     #### ####            ####  ###           ####     #### ####     ###    ####     ####  ####     ####  ###            ####   ###      ##  ####     ####  ###    ####    ####     ####  ####     ####   ###      ##   ####    ###    ##   ####     ####   ###########   ####     ####  ####     ####    ###    ##    ####       ###     ######    #####    ##    #### ######    ###########    #####      ###      ######

第七题:http://www.pythonchallenge.com/pc/def/channel.html

从这里下载zip包:http://www.pythonchallenge.com/pc/def/channel.zip

读zip包中的readme文件,可以知道题目意思和上面第5道题类似:

import urllib, zipfile, re, collectionso, n, f = [], "90052", "%s.txt"nnr = "Next nothing is (\d+)"# Download the ZIP file from http://www.pythonchallenge.com/pc/def/channel.zipfile = zipfile.ZipFile("channel.zip")while True:    try:        n = re.search(nnr, file.read(f % n)).group(1)    except:        print file.read(f % n)        break    o.append(file.getinfo(f % n).comment)print "".join(o)
这道题,貌似有些小问题,我是没有收集到comment信息.

GitHub源码地址

1 0
原创粉丝点击