閱讀1014 返回首頁    go 阿裏雲 go 技術社區[雲棲]


pythonchallenge_level1

level1

地址:www.pythonchallenge.com/pc/def/274877906944.html
源碼:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
問題:算字母後麵第二個字母。

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# Level 1

def fun(sc):
    sc = ord(sc) + 2
    if sc > 122:     #122=z
        sc = sc -26
    return chr(sc)


b = str.maketrans("abcdefghijklmnopqrstuvwxyz", "cdefghijklmnopqrstuvwxyzab")
src = u"map"
print("Level 1:", "".join(list(map(fun, src))))
print("Level 1:", src.translate(b))

ord()得到字符對應的ascii碼。
chr()得到ascii對應的字符。
'z'對應122,y,z的後麵第二位減去26可以得到a,b。
fun是自己寫的函數,作為參數傳給map函數。

最後更新:2017-10-01 07:33:14

  上一篇:go  pythonchallenge_level2
  下一篇:go  pythonchallenge_level0