gpt4 book ai didi

python - 字母表中的下一个字母

转载 作者:太空宇宙 更新时间:2023-11-04 04:17:42 25 4
gpt4 key购买 nike

我在 cs circles 问题 Next Letter 上卡住了如何让 Z 变成 A

x =input()

x=x.upper()

x=chr(ord(x) + 1)

print(x)

如何让 z 变成 A?

最佳答案

使用 chrord:

def next_alpha(s):
return chr((ord(s.upper())+1 - 65) % 26 + 65)

for s in 'abcdefghijklmnopqrstuvwxyz':
print('%s --> %s' % (s, next_alpha(s)))

a --> B
b --> C
...
y --> Z
z --> A

关于python - 字母表中的下一个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55115070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com