清风竹林

ぷ雪飘绛梅映残红
   ぷ花舞霜飞映苍松
     ----- Do more,suffer less

Python Challenge lv1: What about making trans?

  题目链接:http://www.pythonchallenge.com/pc/def/map.html
  由于仅仅是第二道题,所以题目还是很易懂的,按图片中的指示,将每个字母替换成它在字母表中顺延两位的那个字母就可以了,解答如下:、

def trans(char):
    
'''Translate a letter as the one two places after it'''
    
if char.isalpha():
        
return chr((ord(char)- ord('a'+ 2)%26 + ord('a'))
    
return char

if __name__ == '__main__':
    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(''.join(map(trans, text)))

  打印结果: 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.


  参考答案链接

posted on 2009-05-11 15:05 李现民 阅读(596) 评论(0)  编辑 收藏 引用 所属分类: python


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理