我需要以下代码的帮助:
def mutate_string(string, position, character):
res=list(string)
res[position] = 'character'
s=''.join(res)
print(s)
a = str(input())
b,c = input().split()
mutate_string(a,b,c)
当我尝试不使用拆分功能而将b
和c
分别作为输入时,输出似乎很好,但是一行中的多个输入会引发以下错误:
abcdefg
5 h
Traceback (most recent call last):
File "C:/Users/Bhargav/.PyCharmCE2018.1/config/scratches/scratch_27.py",
line 11, in <module>
mutate_string(a,b,c)
File "C:/Users/Bhargav/.PyCharmCE2018.1/config/scratches/scratch_27.py",
line 3, in mutate_string
res[position] = 'character'
TypeError: list indices must be integers or slices, not str