我打算在竞争性编码网站上解决以下问题,我必须将' - >'转换为'。'。只在代码部分但不在注释中。 https://www.hackerearth.com/problem/algorithm/compiler-version-2/IndexError:python中的索引超出范围
我试图写一个解决方案,但每次我运行它它给了我IndexError消息。一些帮助非常感谢。下面是我的解决办法
import copy
temp_list = []
while True:
string = input()
if string != "":
temp_list.append(string)
string = None
else:
break
for i in range(len(temp_list)):
j = 0
while j <= (len(temp_list[i]) - 2):
if string[i][j] == '-' and string[i][j + 1] == '>':
#print("Hello WOrld")
temp_string = string[i][:j] + '.' + string[i][j + 2:]
string[i] = copy.deepcopy(temp_string)
elif string[i][j] == '/' and string[i][j + 1] == '/':
#print("Break")
break
else:
#print(j)
j += 1
for i in temp_list:
print(i)
你能发布完整的错误追溯? – Harrison
这里有很多问题,不知道从哪里开始 – mic4ael