码迷,mamicode.com
首页 > 编程语言 > 详细

使用python 3.x 对pythonchallenge-----1的解答过程

时间:2017-09-01 15:04:27      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:translate   int   bcb   调整   imp   pre   str   rcc   python   

pythonchallenge-1地址 : http://www.pythonchallenge.com/pc/def/274877906944.html
图片如下:
技术分享

题目解析:看图也不懂是什么意思,于是看一下攻略。题目意思:把每个字符位移两次,例如:K→M
解题过程:
import re

def charshitf(aa):
    p1=re.compile(‘[a-x]‘)
    if p1.match(aa):
        return chr(ord(aa)+2)
    elif aa == ‘y‘:
        return ‘a‘
    elif aa == ‘z‘:
        return ‘b‘
    else:
        return aa

straa = "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. "
strbb = ""
strcc = "map"
for i in strcc:
    strbb = strbb +charshitf(i)
print(strbb)
答案:通过解译页面的文本内容得出: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字符即可,map→ocr
心得:使用了正则表达式,引用了re。
  整个程序不够简练,等有空了在来调整一下

使用python 3.x 对pythonchallenge-----1的解答过程

标签:translate   int   bcb   调整   imp   pre   str   rcc   python   

原文地址:http://www.cnblogs.com/yinsjun/p/7463170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!