【发布时间】:2021-11-17 16:11:57
【问题描述】:
我想使用 python 移动字母表中的每个字母(例如 a→b,b→c,...)。当你写一个像“汽车”这样的词时,它会改变字母,新词是“Dbs”(C→D, a→b, r→s)。到目前为止,这是我的代码,但它不起作用并且效率不高:
def shift(letter):
switch={
"a":"b",
"b":"c",
"c":"d",
"d":"e",
"e":"f",
"f":"g",
"g":"h",
"h":"i",
"i":"j",
"j":"k",
"k":"l",
"l":"m",
"m":"n",
"n":"o",
"o":"p",
"p":"q",
"q":"r",
"r":"s",
"s":"t",
"t":"u",
"u":"v",
"v":"w",
"w":"x",
"x":"y",
"y":"z",
"z":"a"
}
return switch.get(letter,"Invalid input")
shift("c")
【问题讨论】:
标签: python python-3.x encoder letter alphabet