易截截图软件、单文件、免安装、纯绿色、仅160KB

穿越Python Challenge

 第九关 Image
    从页面上的图片可以看到有一串点,那么是不是代表该关与图像点有关? 我们从页面源码可以看到,有两段数字序列first和second,而有一个提示first+second=? 什么意思呢?难道是说(first, second)代表了图像点的坐标?不像,两段序列的长度有很大差异。那么算符+还有什么含义呢,有可能是将两段序列拼起来,然后每两个数字代表一个图像点。通过处理,我们在原图片上按照给定的坐标涂黑点,却发现什么都看不清;因此我们按照图片的规格新建一个图片,在黑底上涂白点,处理程序如下:
#!/bin/python
# file: good.py

import re, Image

file = open('d:\Python\good.html')
message = re.findall('(<!--[^-]+-->)', file.read(), re.S)[1]
file.close()

first = re.findall('(\d+)',re.findall('first:(.+)second',message,re.S)[0],re.S)
second = re.findall('(\d+)',re.findall('second:(.+)>',message,re.S)[0],re.S)

all = first + second

im = Image.open('d:\Python\good.jpg')
im2 = Image.new(im.mode, im.size)

for x in range(0,len(all),2):
im2.putpixel((int(all[x]),int(all[x+1])),(255,255,255,255))
im2.show()

    结果出现一只牛的图样,根据英文拼写,我们得到cow单词,进入页面 ,得到提示“hmm. it's a male. ” 雄性的牛?公牛bull,进入页面 ,通关!
第十关 序列推理
    图片下方有一串字符“len(a[30]) = ?”,学过编程的都会意识到a可能是一个以字符串为元素的列表。那么a从哪里来呢?我们看页面源码,发现有一个href链接,打开网页 ,我们得到提示“a = [1, 11, 21, 1211, 111221, ”。很显然,这需要我们从已有的数字序列中找到规律,继而计算出第31个元素。通过思考,发现每个元素其实就是按顺序对前一个数字序列的解释,比如说“21”包含了1个2,1个1,因此下一个元素是‘2111’,按照这种规律,‘111221’包含了3个1,2个2,1个1,因此下一个元素应该是‘312211’,我们编写代码如下:
#!/bin/python
# file: getLength.py

strings = ['1','11']

for i in range(1,31):
j = 0
string = ''
while j < len(strings[i]):
count = 1


相关文档:

Python入门的36个例子——05 聪明的变量

# 005
# 在Python中给变量赋值时不需要声明数据类型
i = 33
print i
# 可以这样做的原因是Python把程序中遇到的任何东西都看成是对象(连int也不例外)
# 这样,在使用对象时,编译器会根据上下文的环境来调用对象自身的方法完成隐式的转换
# 你甚至可以把程序写成这样
print 3 * 'haha '
# 但若写成这样编译器就会报错 ......

Python入门的36个例子 之 24

# 027
toolName = 'Google'
if toolName.startswith('Go'):
print 'The tool\'s name starts with \"Go\".'
if 'oo' in toolName:
print 'The tool\'s name contains the stirng "oo".'
print toolName.find('gl') # 返回首次出现“gl”字符串的索引
if toolName.find('Baidu ......

Python入门的36个例子 之 28

源代码下载:下载地址在这里
# 032
# 其实cPickle这个模块起到的作用可以用“完美地协调了文件中的内容(对象)和代码中的引用”来形容
import cPickle as p # 这条语句给cPickle起了个小名p
objectFileName = r'C:\Data.txt'
aList = [1, 2, 3]
f = file(objectFileName, 'w')
p.dump(aList, f)
f.close ......

Python入门的36个例子 之 35

源代码下载:下载地址在这里
# 039
while True:
try:
x = int(raw_input('Input a number:'))
y = int(raw_input('Input a number:'))
z = x / y
except ValueError, ev:
print 'That is not a valid number.', ev
except ZeroDivisionError, ez:
print 'Di ......

Python入门的36个例子 之 36

# 040
import time
try:
f = file('040_Finally.py')
while True:
line = f.readline()
if len(line) == 0:
break
time.sleep(0.33)
print line,
# end of while
finally:
f.close()
print 'Closed the file.'
# end of try
output:
> ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号