Python Challenge闯关游戏——持续更新
来源:互联网 发布:什么软件看美剧最全 编辑:程序博客网 时间:2024/06/06 09:39
Python Challenge是一个网页版在线闯关游戏,该系列一共有33个项目,每一关都需编写程序寻找答案以通关。本文基于Python2.7,利用PyCharm工具记录了典型通关题目的解决方案,持续更新中…
Level1: 位移加密
//ch1_map.py, ocrimport stringtext = "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 my_solution(test):# o = ""# for each in text:# if ord(each) >= ord('a') and ord(each) <= ord('z'):# o += chr((ord(each) + 2 - ord('a')) % 26 + ord('a'))# else:# o += each# print odef std_solution(test): table = string.maketrans( string.ascii_lowercase, string.ascii_lowercase[2:] + string.ascii_lowercase[:2] ) print string.translate(test,table)if __name__ == '__main__': std_solution(text) std_solution("map")
Level2: 字符识别
//方案一 ch2_ocr.py, equalityimport string# text = open('ch3_mess.txt').read()## def my_solution(test):## s=filter(lambda x:x in string.letters,test)# print ss = ''.join([line.rstrip() for line in open('ch3_mess.txt')])occ={}for c in s: occ[c] = occ.get(c, 0) + 1avgOC = len(s) // len(occ)if __name__ == '__main__': print ''.join([c for c in s if occ[c] < avgOC])
//方案二 Using Beautiful Soup>>> import urllib>>> import BeautifulSoup as bs>>> churl = "http://www.pythonchallenge.com/pc/def/ocr.html">>> full = urllib.urlopen(churl).read()>>> src = bs.BeautifulSoup(full)>>> comments = src.findAll(text=lambda text:isinstance(text, bs.Comment))>>> clue = comments[1]>>> for l in clue:... c = clue.count(l)... if c < 5: print l, "(", c, ")", ... e ( 1 ) q ( 1 ) u ( 1 ) a ( 1 ) l ( 1 ) i ( 1 ) t ( 1 ) y ( 1 )
阅读全文
0 0
- Python Challenge闯关游戏——持续更新
- python challenge 游戏闯关 学习1
- python challenge 游戏闯关 学习2
- Python学习—持续更新
- python闯关3——国际象棋问题
- python闯关4——最大最小
- python练题--游戏式闯关挑战
- PythonChallenge闯关游戏——第0关
- PythonChallenge闯关游戏——第1-5关
- PythonChallenge闯关游戏——第6-10关
- PythonChallenge闯关游戏——第11-15关
- PythonChallenge闯关游戏——第16-20关
- 闯关游戏
- python闯关
- Python闯关
- Python 闯关
- Python Challenge攻略(更新到5)
- python challenge 过关心得 逐步更新
- c#快速入门2
- CSS 块级元素 行内元素
- 机器学习实战 决策树
- 二、策略模式——设计模式学习笔记
- 20. Valid Parentheses
- Python Challenge闯关游戏——持续更新
- Linux—基本命令
- RecyclerView回收机制分析--“取”
- shell脚本中的eval、‘‘和$()
- 描述符表(descriptor table) 学习总结
- 王一题一题一题题
- 数据库设计范式
- sprintf在51单片机中转换字符出错问题解决
- OkHttp Wiki翻译(五)拦截器