gwuj 发表于 2017-4-24 09:55:57

Python Challenge Level 1 ~ 2

  Python Challenge,一个Programming Game的Site,没事玩玩。
  Level-1:
  http://www.pythonchallenge.com/pc/def/map.html
  字符字典,先翻译hints。

#!/usr/bin/python
import string
"""
Python Challenge, Level 1:
http://www.pythonchallenge.com/pc/def/map.html
"""
def main():
dictionary = {ord(string.ascii_lowercase): \
ord(string.ascii_lowercase[(i+2)%26]) for i in range(26)}
text = '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.'
print(text.translate(dictionary))
if __name__ == '__main__':
main()
  根据hints的释义,对url的尾字符串“map”应用该字典转义即可进入下一个level。
  Level-2:
  http://www.pythonchallenge.com/pc/def/ocr.html
  根据hints,查看Page source code后得知是字符查找问题。

#!/usr/bin/python
import urllib.request
import re
"""
Python Challenge, Level 2:
http://www.pythonchallenge.com/pc/def/ocr.html
"""
def main():
url = 'http://www.pythonchallenge.com/pc/def/ocr.html'
resp = urllib.request.urlopen(url).read().decode()
matches = re.findall(r'<!--(.*?)-->', resp, re.DOTALL)
result = ''.join(re.findall(r'', matches))
print(result)
if __name__ == '__main__':
main()

  得出答案:equality。替换url,顺利进入下一关。
页: [1]
查看完整版本: Python Challenge Level 1 ~ 2