The Python Challenge 0-4

项目地址:http://www.pythonchallenge.com/

Level-0

提示Hint: try to change the URL address. ,修改0.html1.html,提示2**38 is much much larger. ,打开python控制台,计算后替换1.html274877906944.html,进入下一关。

>>> 2**38
274877906944

Level-1

提示everybody thinks twice before solving this.,观察图片发现是一道找规律的数学题,字母间位置相差2,由此猜测位移计算,将字符串中所有字母右移两位。

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. "

def right_2(str):
if str is 'y':
return 'a'
if str is 'z':
return 'b' if str.isalpha() and str not in 'yz':
return chr(ord(str)+2)
return str
s = map(right_2, str)
print ''.join(s)

ord() 函数以一个字符(长度为1的字符串)作为参数,返回对应的 ASCII 数值。

chr() 用一个范围在 range(256)内的(就是0~255)整数作参数,返回一个对应的字符。

isalpha() 方法检测字符串是否只由字母组成。

map() 会根据提供的函数对指定序列做映射。第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。

程序运行结果为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. ,根据提示添加str = "map",运行得到结果ocr

解法二:

根据提示的函数,maketrans() 方法用于创建字符映射的转换表,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标。两个字符串的长度必须相同,为一一对应的关系。

生成字母表

>>> import string
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'

操作字符串自定义规则

import string
from string import maketrans
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. " def right_2(str): s = string.ascii_lowercase
s1 = s
s2 = s[2:26] + s[0:2] trantab = maketrans(s1,s2)
if str.isalpha():
return str.translate(trantab)
return str
str = map(right_2,str)
print ''.join(str)

Level-2

提示recognize the characters. maybe they are in the book,but MAYBE they are in the page source.,直接查看源代码提示find rare characters in the mess below,复制后保存到文件,程序如下,运行结果为equality

import string

l = []
with open('/Users/markzhang/Desktop/level3.txt','r') as f:
str = f.read()
for s in str: if s in string.ascii_lowercase:
l.append(s)
if s in string.ascii_uppercase:
l.append(s)
print ''.join(l)

Level-3

提示One small letter, surrounded by EXACTLY three big bodyguards on each of its sides. ,要求查找类似xXXXxXXXx的小写字母,直接查看源代码,复制后保存到文件,程序如下,运行结果为linkedlist

import re

with open('/Users/markzhang/Desktop/level4.txt','r') as f:
str = f.read()
pattern = re.compile(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')
result = re.findall(pattern,str)
print ''.join(result)

Level-4

打开是一张图片,点击图片提示and the next nothing is 44827,替换为nothing=44827后提示and the next nothing is 45439,继续替换时提示Your hands are getting tired and the next nothing is 94485,猜测是请求发包次数的问题,回到显示图片页面,查看源码提示urllib may help. DON'T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough.,尝试获取noting的值,循环发包获取答案。

import requests
import re p = '12345' def next_index(p):
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s' %p
res = requests.get(url).content
pattern = re.compile(r'\d+')
index = re.search(pattern,res).group()
return index for i in range(1,401):
print 'the %d time' %i
p = next_index(p)
print p

运行到86次报错,访问第85次的nothing16044,提示Yes. Divide by two and keep going.

根据提示除以二后使用8022继续访问,提示and the next nothing is 25357,赋值p后继续运行上面的程序,运行到55次出错,访问此时结果82683,提示You've been misleaded to here. Go to previous one and check.

根据提示继续访问上一次运行结果82682,提示There maybe misleading numbers in the text. One example is 82683. Look only for the next nothing and the next nothing is 63579,继续访问63579,提示and the next nothing is 37278,赋值p后继续运行上面的程序,运行到109次报错,使用108次的值66831继续访问,得到peak.html

The Python Challenge 0-4的更多相关文章

  1. Python Challenge 过关心得(0)

    最近开始用Openerp进行开发,在python语言本身上并没有什么太大的进展,于是决定利用空闲时间做一点python练习. 最终找到了这款叫做Python Challenge(http://www. ...

  2. python challenge第1关--NoteBook上的“乱码”

    在 python challenge第0关中已经得到第1关的地址了: http://www.pythonchallenge.com/pc/def/map.html 一.观察地址栏和标签: What a ...

  3. Python Challenge 第四题

    这一题没有显示提示语,仅仅有一幅图片,图片也看不出什么名堂,于是直接查看源代码,源代码例如以下: <html> <head> <title>follow the c ...

  4. The Python Challenge 谜题全解(持续更新)

    Python Challenge(0-2) The Python Challengehttp://www.pythonchallenge.com/ 是个很有意思的网站,可以磨练使用python的技巧, ...

  5. Python Challenge 第一关

    偶然在网上看到这个,PYTHON CHALLENGE,利用Python语言闯关,觉得挺有意思,就记录一下. 第0关应该算个入口吧,试了好几次才试出来,没什么代码就不写了.计算一个结果出来就行. 第一关 ...

  6. The Python Challenge 闯关笔记

    The Python Challenge : http://www.pythonchallenge.com/ Level 0: 看提示图片中为2**38,计算值为274877906944. Hint: ...

  7. python 2.4 与 python 3.0 的比较

    转过来,留着日后查看 [转自:]http://hi.baidu.com/autoitcn/blog/item/5f41973294b5fc4fac4b5f77.html python 2.4 与 py ...

  8. Python 3.0(一) 简介

    Python 3.0(一) 简介 [目录] 1.简介 2.python特点 3.安装 简介: Python是可以称得上即简单又功能强大的少有的语言中的一种.你将会惊喜地发现,专注于问题的解决方案而不是 ...

  9. HOWTO Use Python in the web — Python v3.0.1 documentation

    HOWTO Use Python in the web - Python v3.0.1 documentation mod_python¶ People coming from PHP often f ...

随机推荐

  1. linux服务之apache篇(一)

    1.apache介绍:使用率最高的网站服务器: URL:统一资源定位符: 端口:http:80   https:443 2.apache三种工作模式: prefork:一个线程处理一个请求(占用内存多 ...

  2. 三台linux集群hadoop,在此上面运行hive

    ---恢复内容开始--- 一,准备 先有三台linux,对hadoop集群的搭建. eddy01:开启一个hdfs的老大namenode,yarn的老大ResourceManager其中进程包括(No ...

  3. Permanent Space 和 Heap Space

      JVM堆内存 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...

  4. uva-10041-水题

    题意:有个人想找到个房子住,并且他经常去其他街道,输入n条街,给这个人选择一条街,使得他去其他街道的距离总和最小. 排序,双重for #include <string> #include& ...

  5. postgres on linux red hat 7 配置问题

    记录几个重点的东西吧,具体的步骤 不上了,网上有很多, 1.  redhat subscripiton需要订阅,没钱的需要去更换yum 源,也很简单,就是把自带的yum给删掉,重装其他的,大家可以百度 ...

  6. 《Spring_Four》第二次作业 基于Jsoup的大学生考试信息展示系统开题报告

    一.项目概述 该项目拟采用Jsoup对大学生三大考试(考研.考公务员.考教师资格证)进行消息搜集,研发完成一款轻量级的信息展示APP,本项目主要的创新点在于可以搜集大量的考试信息,对其进行一个展示,而 ...

  7. Quartz基础知识了解(一)

    一.QuartZ是什么? 二.获取 三.核心接口 Scheduler - 与调度程序交互的主要API. Job - 由希望由调度程序执行的组件实现的接口. JobDetail - 用于定义作业的实例. ...

  8. ProxyHandler处理器(代理设置)

    很多网站会检测某一段时间某个IP的访问次数(通过流量统计,系统日志等),如果访问的次数多得不像正常人,它会禁止这个IP的访问. 所以我们可以设置一些代理服务器,每个一段时间换一个代理,就算IP被禁止, ...

  9. python--第十天总结(IO多路复用)

    服务器端编程经常需要构造高性能的IO模型,常见的IO模型有四种: (1)同步阻塞IO(Blocking IO):即传统的IO模型. (2)同步非阻塞IO(Non-blocking IO):默认创建的s ...

  10. 计算a月的第b个星期c

    计算从y1到y2年a月的第b个星期c的日期 #include<iostream> using namespace std; bool isLeap(int y) { == || y%==& ...