
直接上代碼(精簡版)
#字母對應數字
dic = {"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7,"i":8,"j":9,"k":10,"l":11,"m":12,"n":13,"o":14,"p":15,"q":16,"r":17,"s":18,"t":19,"u":20,"v":21,"w":22,"x":23,"y":24,"z":25}
#列印時使用該字串
cha = "abcdefghijklmnopqrstuvwxyz"
list1 = list(input("\n請輸入一串字母:"))
i = eval(input("請輸入偏移量(0-26):"))
if i >=0 and i <=25:#偏移并直接輸出
print("偏移量%d:" % (i),end=" ")
for j in list1:
#python三目運算子(條件為真時的結果 if 判段的條件 else 條件為假時的結果)
print(cha[dic.get(j)+i - 26 if (dic.get(j)+i > 25) else dic.get(j)+i],end="")
運行結果

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/194024.html
標籤:python
上一篇:小波閾值去噪
