我打算在競爭性編碼網站上解決以下問題,我必須將' - >'轉換爲'。'。只在代碼部分但不在註釋中。 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