python中的字符串的一个问题

python中的字符串的一个问题

问题描述:

输入一串字符,修改其中的数字后将字符串输出
修改要求如下:
0123456789—>2345678901
(用上ord、chr)

你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)

s = input()
s = list(s)
for i in range(len(s)):
    if s[i].isdigit():
        c = ord(s[i]) + 2
        if c>ord("9"):
            c -= 10
        s[i] = chr(c)

s = "".join(s)
print(s)