2012年1月19日星期四

pythonchallenge 通关秘籍 Level 2

url: http://www.pythonchallenge.com/pc/def/map.html
题目图片上写着:
K ---> M
O ---> Q
E ----> G
实际上是对每一个字母的ascii编码 + 2
In [6]: str_list=['K','M','O','Q','E','G']

In [7]: for x in str_list:
   ...:     print 'ascii code:',ord(x),'chr:',x
   ...:    
   ...:    
ascii code: 75 chr: K
ascii code: 77 chr: M
ascii code: 79 chr: O
ascii code: 81 chr: Q
ascii code: 69 chr: E
ascii code: 71 chr: G

代码:
import string
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."
table=string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab')
print str.translate(table)
执行结果:
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转换为ocr
然后进入第二关:http://www.pythonchallenge.com/pc/def/ocr.html




pythonchallenge 通关秘籍 Level 1

学习python的朋友,可以去http://www.pythonchallenge.com 网站看看
下面说说Level 1的通关秘籍:
url: http://www.pythonchallenge.com/pc/def/0.html
答案:按照图片上说的计算2的38次方。
进入ipython:
In [2]: 2**38
Out[2]: 274877906944L

现在修改url地址:http://www.pythonchallenge.com/pc/def/274877906944.html

通关!