用户:
梦之泪伤10086查看:0 回复:1 评论:0 创建时间:2021-04-17T16:31:29
【作品展示】

【作品介绍】
oh no
【作品源代码】
s = input('请输入字符串:')
s = s.lower()
c1 = input('请输入要替换的字符串')
c1 = c1.lower()
c2 = input('请输入替换成的字符串')
new = ''
newtmp = ''
found = 0
n = 0
for i in range(len(s)):
if (s[i] == c1[0] and found == 0):
found = 1
newtmp = new
if (found == 1):
if (s[i] != c1[n]):
found = 0
else:
n = (n + 1)
if (found == 1 and n == len(c1)):
new = (newtmp + c2)
else:
new = (new + str(s[i]))
if (n == len(c1)):
found = 0
n = 0
print(new)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn
庄nnnn额可以用re模块,更简洁一些
import re
s=input('请输入字符串:').lower()
c1=input('请输入要替换的字符串').lower()
c2=input('请输入替换成的字符串')
print(re.sub(c1,c2,s))点赞0
评论