pythonchallenge 1

本文介绍了一个名为Python Challenge的在线编程解谜游戏,并通过实例解释了如何使用Python处理字符串替换问题,具体展示了如何将字符串中的每个字母替换成字母表中的第三个字母。
 
图片提示:
     k -->  m
     o -->  Q
     e  --> g
其实真正的规律就是 所有的字母替换为字母表中顺序的第三个字母,
比如字母表:
 

alphabet=[ 'a','b','c','d','e','f','g','h','i','j','k','l',\
           'm','n','o','p','q','r','s','t','u','v','w','x','y','z']


将a替换为c  b替换为d

结尾的几个字母,从字母表头开始替换,比如y替换为a  z替换为b

代码:

src ="map 11 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"

alphabet=[ 'a','b','c','d','e','f','g','h','i','j','k','l',\
           'm','n','o','p','q','r','s','t','u','v','w','x','y','z']
dst=""
for i in src:
    #print( i )
    if i.isalpha():
        try:
            index = alphabet.index(i)
            if index <= 22:
                print("<=23 index=%d"%index)
                dst += alphabet[index+2]
            else:
                print(">23 index=%d"%index)
                dst += alphabet[index+2-26]
        except Exception:
            continue
    else:
        dst += i
      
print("dst= %s"%dst)


输出结果是:

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

有意思;

过关:

原始链接为:http://www.pythonchallenge.com/pc/def/map.html

     后缀为map.html,按照上文的道理替换,则新的连接为:

http://www.pythonchallenge.com/pc/def/ocr.html

过关!!

 

阅读(289) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值