0
不知道爲什麼我索引超出範圍錯誤。Python索引超出範圍錯誤
功能應該循環IP地址列表,直到事件值在:
event = ["Birthday-venues", "baby-shower", "wedding", "corp", "party"]
ip = [1, 2, 3]
lip = len(ip)
levent = len(event)
def eventIP():
i = 0
dict = {}
while i < levent:
for j in range(0, lip):
dict[event[i]] = ip[j]
if i < levent:
i += 1
else:
break
print(dict)
eventIP()
錯誤:
Traceback (most recent call last):
File "script.py", line 21, in <module>
eventIP()
File "script.py", line 13, in eventIP
dict[event[i]] = ip[j]
IndexError: list index out of range
您對此有何看法? – TigerhawkT3
當它崩潰時,我和j的值是什麼? – AndreiM
'levent = len(event)-1'呢?如果你這樣做,那麼輸出將是'{'生日場地':1,'派對':2,'嬰兒洗澡':2,'公司':1,'婚禮':3}'。 –