给定一个句子,返回该句子将其字母在字母表中转置为1,但仅当字母为a-y时
# input
'the quick brown fox jumps over the lazy dog'
# output
'uif rvjdl cspxo gpy kvnqt pwfs uif mbzy eph'
我试过这个:
a = [chr(ord(i) + 1) if ord(i) != ord(' ') else i if i =='y' else i for i in input() if ord(i) < ord('z')]
print(''.join(a))
我得到的输出(y
在lazy word中缺少,即mbzy
):
uif rvjdl cspxo gpy kvnqt pwfs uif mbz eph
这项工作:
输出
下面的代码应该可以做到这一点。我更改了一些条件,并删除了结尾(
ord(i) < ord('z')
)处的条件,因为它阻止处理“z”字符此外,比较运算符处理字符和整数,因此在条件中不必总是使用“ord()”
如果我理解了说明,则此代码对我有效:
输出:
相关问题 更多 >
编程相关推荐