PythonChallenge4-7题详解Python版
来源:互联网 发布:数据库如何使用boolean 编辑:程序博客网 时间:2024/06/06 05:45
第4题:http://www.pythonchallenge.com/pc/def/linkedlist.php
点击图片找到链接,根据页面提醒,更改nothing找到下一个链接。。。知道结束,应该是不是数字的时候结束。
根据正则匹配nothing的值应该简单的
import urllib import redef next_url(p): text=urllib.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' + str(p)).read() num=re.match('and the next nothing is ([0-9]+)',text) if not num: print text return num.group(1)num=12345for i in range(400) :num=next_url(num)
根据上面程序中间有需要自己手工更改num的值
下面一的代码和上面的差不多,但是这两个程序我都没有完整的运行结束,据说是网络的问题。
import urllib import redef next_url(p): text=urllib.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s' %p).read() num=re.search('([0-9]+)',text) if not num: print text print text,num.group(1) return num.group(1)num=12345for i in range(400) : num=next_url(num)
=========================就这样吧======================
第5题链接:http://www.pythonchallenge.com/pc/def/peak.html
至于如何找到题目的,在之前的java写的代码说了下,但是主要还是看别人的博客说的,英语差也没办法的
import urllibdef get_urldata(p): text=urllib.urlopen('http://www.pythonchallenge.com/pc/%s'%p).read() return texttext=get_urldata('def/banner.p')import pickledata=pickle.loads(text)print '\n'.join([''.join([p[0]*p[1] for p in row])for row in data])
对于最后一行,不知道什么意思特别是p[0]*p[1]
for line in pickle.load(data): print ''.join([x[0] * x[1] for x in line])
这样也行,不明白什么意思
================================================================
第6题链接:http://www.pythonchallenge.com/pc/def/channel.html
上面的图片看着很邪恶。。。
http://www.pythonchallenge.com/pc/def/channel.html/zip 下载数据,与第4题差不多的
读取文件:
import zipfileimport StringIOimport urllibimport redef get_challenge(s): return urllib.urlopen('http://www.pythonchallenge.com/pc/' + s).read()z=zipfile.ZipFile(StringIO.StringIO(get_challenge('def/channel.zip')))print z.read('readme.txt')print z.read('90052.txt')
找到最后一个文件的内容:
def nexttxt(p): text=z.read('%s.txt'%p) num=re.search('([0-9]+)',text) if not num:print text return num.group(1)p=90052for i in range(len(z.namelist())): p=nexttxt(p)
Collect the comments.
Traceback (most recent call last):
File “”, line 3, in
File “”, line 5, in nexttxt
AttributeError: ‘NoneType’ object has no attribute ‘group’
继续:
zp=[]p=90052for i in range(len(z.namelist())): zp.append(p)#文件名连接起来了 p=nexttxt(p)print ''.join([z.getinfo('%s.txt' % p).comment for p in zp])
或者:
zc=[]for p in zp: zinfo=z.getinfo('%s.txt'%p) zc.append(zinfo.comment)print zcprint ''.join(zc)
zc就是输出的结果:HOCKEY
================说明=================
string.join(seq):Merges (concatenates)以 string 作为分隔符,将 seq 中所有的元素(的字符串表示)合并为一个新的字符串
comment :获取文件的注释,具体怎么找到,我也不知道了
zinfo=z.getinfo(‘%s.txt’%p):获取信息
=============================================================
第7题链接:http://www.pythonchallenge.com/pc/def/oxygen.html
图片中的那条马赛克按照ASCII解码
读取图片信息:
import urllibimport refrom PIL import Imagedef get_challenge(s): return urllib.urlopen('http://www.pythonchallenge.com/pc/' + s).read()def get_image(s): return Image.open(StringIO.StringIO(get_challenge(s)))p='def/oxygen.png'im=get_image(p)im=Image.opem('http://www.pythonchallenge.com/pc/def/oxygen.png')
查看图片大小:print im.size (629,95)
下面我就不知道怎么搞的了
print ''.join([chr(im.getpixel((i, 47))[0]) for i in xrange(0, 625,7)]) print ''.join(map(chr, [105, 110, 116, 101, 103, 114, 105, 116, 121]))
对于输出:
“`
print ”.join([chr(im.getpixel((i, 47))[0]) for i in xrange(0, 625,7)])
smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]pe_
print ”.join(map(chr, [105, 110, 116, 101, 103, 114, 105, 116, 121]))
integrity
`
第8题就是Integer.html
====================================
搞到了第8题了,几乎都是网上整理的程序,对Python所需学的东西还是很多的。下面要整理下所需的Python模块资料。
- PythonChallenge4-7题详解Python版
- GeoIP的详解 --Python版
- 【详解】Python统一解密改进版
- 【详解】Python脚本转可执行文件进阶版
- Python 第二版答案详解全集
- PythonChallenge0-3题详解Python版本
- Python Tip(31~35)题详解
- Python Tip(41~45)题详解
- Python Tip(46~50)题详解
- Python Tip(51~55)题详解
- Python模块详解
- Python 字符串方法详解
- Python模块详解
- Python 字符串方法详解
- python中%符号详解
- python time模块详解
- Python字符编码详解
- Python 字符编码详解
- java编写微信公众账号收发消息
- 只遍历一次,将单链表中的元素顺序反转过来
- javascript之jquery基础 选择器
- 深度学习(一)深度学习学习资料
- Visual Studio 相关错误
- PythonChallenge4-7题详解Python版
- javascript之jquery DOM操作
- 游戏主程序亲述游戏职场生涯
- 2045 不容易系列之(3)—— LELE的RPG难题
- 面向对象三要素
- CUDA的Threading:Block和Grid设定
- javascript之jquery 事件
- android 按后退键,最小化程序(不退出AC)
- javascript之jquery 动画